Say somewhere in my Vim buffer that I have the following:

function foo() {
    return 'funday, funky, funnel cake';
}

Now I want to create a new function below this..

I start typing fun and hit Tab to bring up my autocomplete menu. In that menu, I get (in this hypothetical order):

funday
funnel
function
funky

Normally, I would Ctrl + n twice to highlight function, which isn't a big deal.. but what if I have 20 results and I want to get to the 10th result really fast.

Is there any known way (or plugin) to quickly jump to specific values in a Vim autocomplete menu?


Update: Using a hack, I found a way to jump by X autocomplete options:

" j/k for up and down in autocomplete menu
inoremap <expr> j ((pumvisible())?("\<C-n>"):("j"))
inoremap <expr> k ((pumvisible())?("\<C-p>"):("k"))

" Hack to jump down x positions
inoremap <expr> 2 ((pumvisible())?("\<C-n><C-n>"):("2"))
inoremap <expr> 3 ((pumvisible())?("\<C-n><C-n><C-n>"):("3"))
inoremap <expr> 4 ((pumvisible())?("\<C-n><C-n><C-n><C-n>"):("4"))

However, my vimscript is gross. Anyone got a better way to do this?

有帮助吗?

解决方案

maybe you are interested in neocomplcache plugin

其他提示

As far as quickly jumping to a specific autocomplete, I have the following workflow.

In my .vimrc:

set completeopt=longest,menuone

The longest option prevents the first match from being automatically selected. This means Vim will wait for you to finish typing the rest of the word, and the completion popup will automatically narrow as you type more characters of the word.

In your example, you would type fun, hit Tab, to bring up your autocomplete menu. At this point, you would still see:

funday
funnel
function
funky

...but now the first choice (funday) would no longer be automatically chosen. You could then type "c", which would narrow the list to:

function

This is the fastest way that I know of, using pure Vim, anyway. I tend to like pure Vim solutions, myself. :)

EDIT: Realized that I forgot to include "menuone" at the end of the line in my .vimrc file. This causes Vim to show the autocomplete menu, even if there was only one match. You would need either "menuone" or "menu" in the set completeopt line in order to actually see the popup with completions.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top