How to auto-complete JavaScript syntax in Vim

JavaScript is the scripting language for the web. Vim in the other hand is the editor of choice for many programmers. Being feature-rich, Vim is able to auto-complete JavaScript syntaxes. To use the feature, you'll need to enable it first.

Enter the following while in Vim's command mode to enable the feature.

:set omnifunc=javascriptcomplete#CompleteJS

You can now auto-complete JavaScript syntaxes by pressing Ctrl + x followed by Ctrl + o while partially typing JavaScript codes.

The following is a sample screenshot.

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

Automatically enable auto-complete for JavaScript files

To automatically enable JavaScript auto-complete every JavaScript file, add the following line to your ~/.vimrc;

autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS

Video tutorial

comments powered by Disqus