Question

I want Vim's completion menu to work more like the one in Visual Studio. I want to be able to write the start of a variable (or something which completion is available), hit the omni-completion keys and get the completion menu. Now I want the completion menu to highlight the best match but not add it to the buffer. Now I want to be able to either hit ENTER to input the selected element or enter more letters to filter the completion menu even more (possibly highlighting a new item in the completion menu) and then hit enter to insert.

The wiki page/tips at http://vim.wikia.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE is supposed to do this but I can't get it to work. Has someone else tried the code from that tip and made it work as I describe?

Was it helpful?

Solution

The referenced wiki page contained broken mappings. A user (Spiiph) changed the Vim code to something that looked better to him, but was not right. I reversed the changes he made and now the inoremap statements should work.

To avoid confusion these are IMHO the right commands:

inoremap <expr> <c-n> pumvisible() ? "\<lt>c-n>" : "\<lt>c-n>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>"
inoremap <expr> <m-;> pumvisible() ? "\<lt>c-n>" : "\<lt>c-x>\<lt>c-o>\<lt>c-n>\<lt>c-p>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>"

PS: When it comes to using Vim's completion feature I found the SuperTab script very convenient. Maybe this script is also interesting for you in this context...

OTHER TIPS

I use supertab, which I really like, and the following seems to work great:

imap <expr> <Tab> pumvisible() ? "<Tab>" : "<Tab><Down>"

For reference: I'm running debian sid, and this works both for vim 7.2.245 and for my patched 7.2.259.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top