2

I installed the plugin tern_for_vim. Followed all the instructions from readme but it doesn't work. I don't have any autocompletion for javascript, the commands :TernDef and :TernDoc are not recognized in vim. I installed the tern server globally using npm and I can launch it.

I tried to launch tern with the --verbose option but it did not output anything when I tried to use autocompletion in javascript files. It seems that there is no communication between vim and the tern server if I understand it correctly.

Here are my plugins in .vimrc file:

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'tmhedberg/SimpylFold'
Plugin 'vim-syntastic/syntastic'
Plugin 'scrooloose/nerdtree'
Plugin 'kien/ctrlp.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'tpope/vim-fugitive'
Plugin 'vim-scripts/indentpython.vim'
Plugin 'nvie/vim-flake8'
Plugin 'davidhalter/jedi-vim'
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
Plugin 'alvan/vim-closetag'
Plugin 'Valloric/MatchTagAlways'
Plugin 'ternjs/tern_for_vim'
Plugin 'lervag/vimtex'

I also setup a .tern-config file in the home directory:

{
    "libs": [
    "ecmascript",
    "browser",
    "jquery"
    ],
    "plugins": {
        "es_modules": {},
    "node": {}
    }
}

I could run ternjs when I set up YouCompleteMe for python autocompletion, but I didn't like it and chose jedi-vim (which is really nice). Now I want to setup javascript autocompletion but without no luck.

Any suggestions how I can solve this problem?

  • 2
    As I often advise on plugin specific questions like this: You should see for help on the plugin's issue tracker: you'll find people who develop/maintain the plugin and use it on a regular basis and who should be able to help you. – statox Aug 24 '17 at 11:24
  • Did you run npm install in the tern_for_vim directory? Furthermore, Tern commands are available only in javascript files. – LEI Aug 24 '17 at 11:58
  • @LEI, Yes I did run npm install inside of the tern_for_vim directory. Before that I installed tern globally as was suggested on issues page of github for this plugin. – Nurjan Aug 24 '17 at 12:05
  • 1
    Try to open a JS file and look for "tern_for_vim" or more specifically <plugin_dir>/tern_for_vim/after/ftplugin/javascript_tern.vim in the :scriptnames output. If you can't find it, the plugin is probably not loaded at all and you should debug your vimrc. – LEI Aug 24 '17 at 12:31
  • 1
    @Nurzhan :set filetype? should be set to javascript. Try to manually execute :call tern#Enable(). – LEI Aug 24 '17 at 13:29
3

Make sure you are editing a JS file (echo &filetype should output javascript), and check the function used for omni completion:

:verbose setlocal omnifunc?

It should display something like:

  omnifunc=tern#Complete
        Last set from ~/.vim/plugged/tern_for_vim/autoload/tern.vim

If not the case, then tern_for_vim/after/ftplugin/javascript_tern.vim may not be loaded (:scriptnames). This file contains the call to tern#Enable() which in turn sets the local &omnifunc to tern#Complete .

To manually enable omni completion (as a quickfix), you could try:

autocmd FileType javascript setlocal omnifunc=tern#Complete

Then start completion in insert mode with <C-x><C-o>.

  • :h compl-omni
  • :h 'omnifunc'
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.