Monday, May 5, 2008

Completion

This is one of my favorite features in Vim. In fact, I use it so often that it didn't occur to me until recently that some people may not take advantage of it. If you're familiar with getting around on a modern shell (bash, csh, zsh, etc...), you're almost certainly acquainted with command completion. Vim offers a similar facility that works on the current buffers you have open (although it can do ex command completion as well ;-). When working in your current window, simply type a portion of a string (i.e., hereIsAReallyLong...) then hit ctrl-n. Vim should display a menu of possible completion options. Scroll up and down the menu with ctrl-p and ctrl-n. Hit enter when you find the entry you want to insert. This saves a lot of typing on longer method names and strings and also helps avoid spelling typos. If you find ctrl-p and ctrl-n too cumbersome to type or simply want to make completion feel more like it does on the shell, you can grab the SuperTab Plugin and use that instead.

Side tip: inside of ex mode, you can just use the tab key to complete your ex commands.

1 comment:

Pento said...

Yes, it's really fantastic feature. Especially omni-completetion in Vim7. I haven't seen any such powerfull text editor...even emacs.