Setup Ternjs Node/Javascript autocomplete plugin for Vim editor

Written on 06 June 2016

Ternjs is a stand-alone code-analysis engine for JavaScript Ternjs. It is an intelligent code completion for javascript.

To use Ternjs you must install Nodejs and Python.

Install TernJS for Vim

Place this in your .vimrc:
For Vundle

Plugin 'ternjs/tern_for_vim'

Then type vim +PluginInstall

cd ~/.vim/bundle  
cd tern_for_vim  
npm install  

For Plug

Plug 'ternjs/tern_for_vim', {'do':'npm install '}

Then type vim +PlugInstall

For pathogen

cd ~/.vim/bundle  
git clone https://github.com/ternjs/tern_for_vim  
cd tern_for_vim  
npm install  

Config Ternjs show autocompletion with Subpertab.
https://github.com/ervandew/supertab

Install Supertab

//Vim bundle
Plugin 'ervandew/supertab'

//Plug Vim plugin manager
Plug 'ervandew/supertab'

//Pathogen
cd ~/.vim/bundle  
git clone https://github.com/ervandew/supertab  


Then add these line to .vimrc

autocmd FileType javascript let g:SuperTabDefaultCompletionType = "<c-x><c-o>"  
set completeopt-=preview  

Add file name .tern-project to your project folder.

{
  "libs": [
    "browser",
    "jquery"
  ],
  "plugins": {
    "requirejs": {
      "baseURL": "./",
      "paths": {}
    },
    "node":{}
  }
}

Now edit some js file and hit tab to show autocompletion
Ternjs for Vim and Supertab

Happy codding