Vim is doing pretty well with syntax JavaScript highlighting out of the box. But it's not ideal. Many of the old syntax plugins for JavaScript have troubles with some modern features like arrow functions or async/await. Here are some plugins that will help to fix it.
It's the Node equivalent of Rails. vim (vimscript #1567) and Rake. vim (vimscript #3669). This is just the first release to get the nodes rolling. If you've collected great helpers and shortcuts that help you work with Node, please share them via email, Twitter or GitHub issues so we could incorporate them here, too!
There is a very easy way to integrate JSLint or the community-driven jshint.com (which is much better IMO) with Vim using the Syntastic Vim plugin. See my other post for more info.
There's also a very neat way to add tag-listing using Mozilla's DoctorJS (formerly jsctags), which is also used in Cloud9 IDE's Ace online editor.
apt-get
, Mac's home brew
, etc.):
exuberant-ctags
ctags
actually runs exuberant-ctags
and not the OS's preinstalled ctags
. You can find out by executing ctags --version
.
2. node
(Node.js)DoctorJS
from github: git clone https://github.com/mozilla/doctorjs.git
DoctorJS
dir and make install
(You'll also need the make
app installed, but this is very basic).make install
doesn't do the trick for the moment. For now I just add the repo's bin/
dir to my $PATH instead. See DoctorJS's GitHub and issues pages for more info.DoctorJS is currently dead. There's a new promising project called tern.js. It's currently in early beta, and should eventually replace it.
There is a project ramitos/jsctags which uses tern as its engine. Just npm install -g
it, and tagbar will automatically use it for javascript files.
snipMate emulates TextMate's ⇥ insertion system and comes with a bunch of useful JS snippets (among others) by default. It's extremely easy to add your own.
javaScriptLint allows you to validate your code against jsl.
Also you can find a variety of JavaScript syntax files on vim.org. Try them and see which one works best for you and your coding style.
The native omnicomplete (ctrlx-ctrlo) works very well for me. You can make it more dynamic with autoComplPop, but it can be annoying sometimes.
edit, in response to tarek11011's comment:
acp doesn't work for JavaScript by default, you have to tweak it a little. Here is how I did it (dirty hack, I'm still a Vim noob):
In vim-autocomplpop/plugin/acp.vim I've added php
and javascript
(and actionscript
) to behavs
so that it looks like that :
let behavs = {
\ '*' : [],
\ 'ruby' : [],
\ 'python' : [],
\ 'perl' : [],
\ 'xml' : [],
\ 'html' : [],
\ 'xhtml' : [],
\ 'css' : [],
\ 'javascript' : [],
\ 'actionscript' : [],
\ 'php' : [],
\ }
A little below, there is a series of code blocks that look like that :
"---------------------------------------------------------------------------
call add(behavs.ruby, {
\ 'command' : "\<C-x>\<C-o>",
\ 'meets' : 'acp#meetsForRubyOmni',
\ 'repeat' : 0,
\ })
I've duplicated this one and edited it a little bit to look like that:
"---------------------------------------------------------------------------
call add(behavs.javascript, {
\ 'command' : "\<C-x>\<C-o>",
\ 'meets' : 'acp#meetsForRubyOmni',
\ 'repeat' : 0,
\ })
and did the same for actionscript and php.
If you want to edit JS/CSS within a HTML document you can do :set ft=html.css.javascript in Vim's command line to make ctrlx-ctrlo work as expected on method/properties names in JS blocks and properties/values in CSS blocks. However this approach has its drawbacks, too (weird indentation…).
This plugin is also useful: https://github.com/maksimr/vim-jsbeautify. It provides full autoformatting for javascript. One keystroke, and your code looks beautiful. It can come in handy when pasting code snippets as well. It makes use of the popular js-beautifier, which can also be found as an online application. The latter can be found right here: http://jsbeautifier.org/.
I only use one js specific vim plugin - jslint.vim - https://github.com/hallettj/jslint.vim which validates your code with jslints rules and gives you syntax errors as well.
To fix indentation and autoformatting (Ctrl =): JavaScript Indent
To set indentation width, add javascript.vim
file into ~/.vim/ftplugin dir with following contents (for two space indentation):
setl sw=2 sts=2 et
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With