Tip 119Autocomplete with Context Awareness

Omni-completion is Vim’s answer to intellisense. It provides a list of suggestions that’s tailored for the context of the cursor position. In this tip, we’ll look at how it works in the context of a CSS file.

Omni-completion is triggered with the <C-x><C-o> command (see compl-omni). The functionality is implemented as a file-type plugin, so to activate it we have to source these lines of configuration:

 set​ nocompatible
 filetype​ plugin ​on

We also have to install a plugin that implements omni-completion for the language that we’re working with. Vim ships with support for about a dozen languages, including HTML, CSS, JavaScript, PHP, and SQL. You can find the full list by looking ...

Get Practical Vim, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.