Recently, I started working on some javascript projects, and I sorely missed autocompletion provided by PyCharm and WebStorm. I found the tern project, which offers powerful javascript autocompletion in vim with YouCompleteMe. Setting it up however, was painful. For others trying to install tern for vim, here are the instructions:
Using vundle, add to your .vimrc:
Plugin "Valloric/YouCompleteMe"
The compile the YCM completion endgine
cd to ~/.vim/bundle/YouCompleteMe
, and run ./install.sh --clang-completer
One of my problems I ran into was when I tried to upgrade YouCompleteMe, and it started crashing after I recompiled it. The problem I had was that it tried to use python 2.7.4 (/usr/local/bin/python) instead of 2.7.5. I fixed it by adding this to my .vimrc:
let g:ycm_path_to_python_interpreter = '/usr/bin/python'
Go to the node.js website and install node.js. I found the homebrew node is not the correct version. Install it with vundle by adding to your .vimrc:
Bundle "marijnh/tern_for_vim"
Run vim +BundleInstall
, and run ~/.vim/bundle/term_for_vim && npm install.
Then, put a .tern-project file in your project directory. It is very finicky, so make sure the syntax is correct. For example, if you try to load a file in tern that is not in the project, autocompletion will not work.
{
"libs": [
"browser",
"underscore",
"jquery"
],
"plugins": {
}
}
This loads semantic completion for the jquery, browser and underscore javascript libraries.
You should be able to use Tern’s autocompletion in vim now. It is quite sophisticated, for a demo visit the tern project site.