I'm new to JS & Vim. Which plugins would help me to write Javascript code?
-
6To give the question more clarity, and to help the OP in their English for future posts... It should read: "Hi, I'm new to JS & Vim. Which plugins would help me to write Javascript code?" You can say "I am new _to_ Javascript and vim". You can use "what is" for singular, so for example "What is _a_plugin_ that would help me..." or you can use "which" for plural like this: "_Which_plugins_ would help me...". Also notice that instead of "plugins _is_" you should use "plugins _would_" because it's a hypothetical. Hope that helps :-) – hendrixski Feb 12 '12 at 19:04
-
3@hendrixski - vote to reopen this. – ocodo Mar 13 '13 at 08:11
-
8Most constructive not-constructive question ever. – Vladislav Zorov Jan 26 '14 at 23:23
-
8I quite enjoy how this "not constructive" question helped me improve a lot my workflow. – MaiaVictor Mar 07 '14 at 06:41
-
Since the question is (unfairly IMO) closed, I'll just add a comment here: there's an electron-based front-end for NeoVim with typescript language server autocompletion out of the box (works with vanilla JS too!): https://www.onivim.io/. It's still a bit rough around the edges but I've been using it as my daily driver for a few weeks now and haven't had too many issues. It has a really good community around it, and it's under _very_ heavy development, so I expect good things from it in the future! Full disclosure: I make a monthly donation to the project and plan to contribute in the future. – Parker Ault Mar 25 '18 at 01:49
5 Answers
Syntax Checking / Linting
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.
Source-Code browsing / Tag-list
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.
- Install the following packages using your favorite package-manager (Ubuntu's
apt-get
, Mac's homebrew
, etc.):exuberant-ctags
- NOTE: After installing make sure running
ctags
actually runsexuberant-ctags
and not the OS's preinstalledctags
. You can find out by executingctags --version
. 2.node
(Node.js)
- Clone
DoctorJS
from github:git clone https://github.com/mozilla/doctorjs.git
- Go inside
DoctorJS
dir andmake install
(You'll also need themake
app installed, but this is very basic).
- There're some bugs with installing the plugin,
make install
doesn't do the trick for the moment. For now I just add the repo'sbin/
dir to my $PATH instead. See DoctorJS's GitHub and issues pages for more info.
- Install the TagBar Vim plugin (NOTE: It's TagBar, not the old infamous TagList!).
- PROFIT. :)
New Project - Tern.js
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.

- 21,988
- 13
- 81
- 109

- 14,716
- 14
- 59
- 66
-
5
-
@RobM: Yeah, it's way better than the old TagList. You're welcome to join it's development at http://majutsushi.github.com/tagbar/ – Ory Band May 30 '11 at 00:32
-
9Currently doctorjs requires you to clone recursive as specified in [this bug](https://github.com/mozilla/doctorjs/issues/12), `git clone --recursive https://github.com/mozilla/doctorjs.git` and then make install should work – Andy Ray Sep 07 '11 at 20:46
-
For anyone trying to use the latest DoctorJS, keep track of this ticket: [jsctags no longer reports scope of tags](https://github.com/mozilla/doctorjs/issues/5) (unresolved as of 10 Jan 2011) – thisgeek Jan 10 '12 at 15:13
-
1doctorjs on Windows: http://baumichel.blogspot.ca/2011/11/how-to-install-doctorjsjsctags-on.html adding additional filetypes to TagBar: https://github.com/majutsushi/tagbar/wiki – Andrew Jun 05 '12 at 18:34
-
6Before doing step 3, cd into doctorjs and do this: `git submodule init && git submodule update`. Then do step 3. – glortho Jul 12 '12 at 12:02
-
2
-
-
-
1@sunglim - This is not TagList's fault - I believe it's a bug in doctorjs which creates the source tree. TagList just shows it on Vim. – Ory Band Oct 13 '12 at 09:45
-
-
-
1It looks like the tern-based solution is out: https://github.com/ramitos/jsctags – Jesse Hallett Sep 25 '13 at 01:23
-
-
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…).

- 186,200
- 21
- 280
- 313
-
-
1Haha, it's . Browsers usually have no default styling for this tag, kudos to the SO team for doing the extra work. – romainl Jan 24 '11 at 09:29
-
thank you romainl , but a have a problem with autoComplPop it is work only with html file no js and css and php – Tarek Saied Jan 24 '11 at 12:48
-
Like a lot of Vim plugins acp is very sensitive to filetypes. If the buffer's filetype is "html", neither acp nor omni complete will work for embedded JS/CSS/PHP. And I'm going to edit my answer, not enough editing options/room here. – romainl Jan 24 '11 at 13:10
-
You may prefer to use the [current maintenance branch of snipMate](https://github.com/garbas/vim-snipmate) that Rok Garbas & co. put together. – thisgeek Jan 09 '12 at 18:07
-
-
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/.

- 14,924
- 14
- 78
- 116
-
3I wrote a general autoformatting plugin for vim which integrates the js-beautifier and more. Check here: https://github.com/Chiel92/vim-autoformat – chtenb Dec 06 '12 at 23:13
-
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.

- 302
- 2
- 11
-
thanks but I think I have a problem look at http://img69.imageshack.us/img69/7629/11142565.png – Tarek Saied Jan 24 '11 at 13:29
-
Hm, on windows there are specific instructions you'll need to follow, it requires a javascript interpreter. I haven't tried installing it on windows, but the install instructions are down the page a bit in the README, sorry I can't be more help there. – Scott Jan 24 '11 at 14:11
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

- 36,389
- 27
- 134
- 170
-
in `~/.vimrc` : `autocmd FileType javascript setlocal sw=2 ts=2 sts=2` – JuanPablo Nov 05 '14 at 14:20