sontek ( John M. Anderson )

June 12, 2008

Vim Tip: Use Ctrl-Space for omni and keyword completion.

Filed under: vim — Tags: — sontek @ 12:19 am

Having Ctrl+Space for auto-completion is great because its a much more natural binding than the vim defaults.

Sometimes omni completion doesn’t find things properly (such as when searching in the current buffer), so I like to fall back to keyword completion if no results are found in omni-completion.

Put this in your .vimrc to get the same effect:

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>

This provides an even more powerful feel to the code completion in vim.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • description
  • Pownce
  • Slashdot
  • StumbleUpon
  • TwitThis

1 Comment »

  1. [...] takahe83 wrote an interesting post today onHere’s a quick excerptHaving Ctrl+Space for auto-completion is great because its a much more natural binding than the vim defaults. Sometimes omni completion doesn’t find things properly (such as when searching in the current buffer), so I like to fall back … [...]

    Pingback by Vim Tip: Use Ctrl-Space for omni and keyword completion. — June 12, 2008 @ 12:30 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress