1

Using Ubuntu 12.

I installed jshint with

sudo npm install jshint -g

which jshint

shows /usr/local/bin/jshint, which is also in the PATH variable

Then, I downloaded https://github.com/walm/jshint.vim/blob/master/plugin/jshint.vim and put it in ~/.vim/bundle/jshint.vim (I am using Pathogen)

Now, when opening a js-File, such as

vim test.js

errors are not detected.

:JSHint 

results in "Not an editor command: JSHint"

:Helptags 

results in, well, nothing.. I don't really see what that command is for, anyway..

I am a vim noob, but other pathogen bundles seem to work, so I do not really know what is not working here..

grssnbchr
  • 2,877
  • 7
  • 37
  • 71

1 Answers1

6

The default way to install plugins is to put their individual pieces in some subdirectories of your ~/.vim/ directory. Taking this plugin as example:

~/.vim/plugin/jshint.vim
~/.vim/doc/jshint.txt

The :Helptags command is used to generate the index (tags) used by Vim to navigate through the documentation of third party plugins. You are supposed to use it like that:

:Helptags ~/.vim/doc

The idea behind Pathogen and other plugin managers is that each plugin should be in its own directory rather than be scattered through your ~/.vim/ directory. In Pathogen's case (and others followed, but there's no standard), that's the bundle directory: ~/.vim/bundle/.

Therefore, the correct location for your plugin should be:

~/.vim/bundle/jshint/plugin/jshint.vim
~/.vim/bundle/jshint/doc/jshint.txt
~/.vim/bundle/jshint/README.md
~/.vim/bundle/jshint/LICENSE

In order for pathogen to work its magic, you are supposed to add these two lines to your ~/.vimrc:

silent! call pathogen#infect()
silent! call pathogen#helptags()

The first line takes care of "registering" and loading each plugin found in ~/.vim/bundle/. The second line indexes their documentation, the equivalent of :Helptags … that you don't need to run, then.

So…

  1. Make sure Pathogen is installed and configured correctly.

  2. Install the JSHint plugin where it should be.

  3. ?

  4. Enjoy writing JavaScript in Vim!


To run :JSHint on the current buffer every time you write it, add this line to your ~/.vimrc:

autocmd! BufWritePost *.js JSHint
romainl
  • 186,200
  • 21
  • 280
  • 313
  • Great, it works. Thanks for your exhaustive answer. Still, I have 1-2 questions. How can I enable JSHint so that everytime I write to a file, (:w), JSHint is executes? Right now it only works when I manually call :JSHint. Secondly, the first error/notice I get in JSHint is the Bad option: 'ender', and I suppose it has something to do with its configuration.. do you know anything about that? – grssnbchr Nov 28 '12 at 07:56
  • 1
    I have no experience with JSHint, you'll have to follow the manual to configure it properly. I'll edit my answer for the `:w`. – romainl Nov 28 '12 at 08:15
  • Check the options you are using to configure jshint. For example, look in ~/.jshintrc and search for the option "ender". If it's there remove it, and it should fix the problem. – cs01 Sep 13 '16 at 22:31