19 May 2009

Omni completion in Vim 7

I just found out about a nifty new feature introduced in Vim 7: omni completion (or, omnifunc). This feature mimics the auto-complete functionality of most IDEs.

From the Vim 7 changelog:

This could also be called “intellisense”, but that is a trademark. It is a smart kind of completion. The text in front of the cursor is inspected to figure out what could be following. This may suggest struct and class members, system functions, etc.

An example with a Python script:

I started typing the exception to raise and invoked omni completion to get a list of matching objects from the module:

if len(r) != 1: raise ldap.NO<Ctrl+X><Ctrl+O>

According to the manual, omnifunc is supported for the following languages:

  • C
  • (X)HTML
  • CSS
  • PHP
  • Python
  • Ruby
  • SQL
  • XML

I’m not sure if it supports Java though - perhaps someone could test and let me know?

This new feature is certainly a time saver, and should definitely help to move some users away from the bloated IDEs.