开发者

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

开发者 https://www.devze.com 2023-02-19 04:21 出处:网络
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\" everyti

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 correc开发者_JS百科t 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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号