Ctrl+Space for omni and keyword completion in vim

Marlun picture Marlun · Feb 4, 2009 · Viewed 10.4k times · Source

I Want to use Ctrl+Space for omni-completion (and keyword completion if there is no omni-completion) in vim. I've tried this which I found somewhere on the web:

inoremap <expr> <c-space> pumvisible() ? "\<C-n>" : "\<C-x>\<C-o>\<C-n>\<C-p>\<C-r>=pumvisible() ? \"\\<Down>\" : \"\\<CR>\""

however it's not working. Anyone who is using Ctrl+Space for this too who can show me the correct way (which works) to do it?

Worth noting is that it needs to work in the terminal version of vim NOT gvim.

Answer

sykora picture sykora · Feb 4, 2009

Try this:

inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
\ "\<lt>C-n>" :
\ "\<lt>C-x>\<lt>C-o><c-r>=pumvisible() ?" .
\ "\"\\<lt>c-n>\\<lt>c-p>\\<lt>c-n>\" :" .
\ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>"
imap <C-@> <C-Space>