How to auto-complete HTML code in Vim

Vim can auto-complete syntax for popular programming languages, including HTML. It is however not enabled by default in most installation.

Entering the following while in Vim's command mode will enable auto-completion for HTML language.

:set omnifunc=htmlcomplete#CompleteTags

To start using the feature, press Ctrl + x followed by Ctrl + o keys while writing HTML syntaxes.

The following screenshot is an example in auto-completing <!

You can use the arrow key to navigate through the list to choose your desired auto-complete suggestion.

Automatically enable auto-complete for HTML files

To enable auto-complete every time a HTML file is opened, add the following line to your ~/.vimrc;

autocmd FileType html set omnifunc=htmlcomplete#CompleteTags

Video tutorial

comments powered by Disqus