I had installed tern_for_vim and YouCompleteMe for js completion this way.
1 install node
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash source ~/.nvm/nvm.sh nvm install node
2 install tern_for_vim
$ cd ~/.vim/bundle git clone https://github.com/marijnh/tern_for_vim
3 install YouCompleteMe
cd ~/.vim/bundle/YouCompleteMe $ ./install.sh --clang-completer --tern-completer
4 edit .tern-project
vim .tern-project { "libs": [ "browser", "underscore", "jquery" ], "plugins": { "node": {} } }
Now to vim test.js.
The js completion pop up after inputing document.
in test.js file.
Then to vim test.html
No js completion pop up after inputing document.
in test.html file.
How to fix it?
2 Answers
Answers 1
Unfortunately this is not officially supported by tern. You can see the response in a closed issue
https://github.com/ternjs/tern_for_vim/issues/170
Because the parsing logic for separating HTML and scripts hasn't been implemented. This could be done as a plugin, if you want to take a shot at it, but it's out of scope for this repository.
But then there is another thread on SO which may help you
Using tern_for_vim plugin in HTML files
So best is to include your code in the html through a JS file and then edit the JS file. Else look at some other plugin/IDE environment. I would explore the below option as well
Answers 2
I'm unfamiliar with tern_for_vim and YouCompleteMe for js completion, however you could always use vim's built in omni-func completion.
If you add:
filetype on filetype plugin on set omnifunc=syntaxcomplete#Complete
to your vimrc file, you can then manually set the filetype of your html file to javascript with :set filetype=javascript
whilst in vim. Following that, when in insert mode, you can then use <C-x>
followed by <C-o>
to access javascript language specific omni completion.
The resulting completion menu is then navigable by the standard <C-p>
for up and <C-n>
for down hotkeys.
This, along with other bits of built in completion functionality are discussed in a nice thoughtbot talk.
0 comments:
Post a Comment