views:

697

answers:

3

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?

+4  A: 

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...

f3lix
A: 

I tried to change to to be able to start omni-completion with ctrl-space but it does not work. It only inserts literal text "c-space" into the buffer. Any ideas anyone?

Marlun
There is actually a question "Ctrl+Space for omni and keyword completion in vim" on stackoverflow which was already answered. I didn't try it out, but I thought it's worth mentioning. Seehttp://stackoverflow.com/questions/510503/ctrlspace-for-omni-and-keyword-completion-in-vim
f3lix
Yeah, I asked it :) But It doesn't work in this case. Will try to figure it all out later.
Marlun
A: 

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.

Zeresh