VIM 7 and cscope: Using “cscope find f” inside a keyboard mapping for switching between files

蹲街弑〆低调 提交于 2019-12-12 18:22:05

问题


I usually hop between files on my cscope-indexed codebase by using

:cscope find f <filename>

I'm trying to define a keyboard shortcut to prevent me having to type ":cscope find f" everytime. Pressing this shortcut would bring up an input prompt, to which I'll enter part of a filename in the cscope database. If there are multiple files, it would show up the list of files, from which I can select the file I want to go to. I've got to this much so far, but since I'm not at all proficient with VIM scripting, I'm unable to complete it. (what I've coded so far is taken from another question, thanks to Eelvex) .

Could someone correct the below script for me ? I'm getting numerous errors while I try to use this shortcut

function! GetPat()
  call inputsave()
  let filename = input("Enter filename: ")
  call inputrestore()
  return filename
endfunction
map ` :cscope find f '.GetPat().'<CR>

回答1:


The mapping won't wait for you to enter the input and then continue. Also, the mapping is wrong, remember that mappings work as if you typed the text, you might get away with something like that using (not tested):

noremap <expr> ` ':cscope find f '.GetPat()."\<CR>"

But why not just:

noremap ` :cscope find f<space>

That would leave you after the last space ready to enter your pattern and just hit enter.



来源:https://stackoverflow.com/questions/5415388/vim-7-and-cscope-using-cscope-find-f-inside-a-keyboard-mapping-for-switching

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!