views:

1278

answers:

3

I'm a pretty new Vim user and I've found that its learning curve is quite steep (at least for me). I just installed this vim script for JavaScriptLint error checking, which shows errors in vim's quickfix window once I save a buffer.

However, I don't know what to do next.. How do I 'scroll' through all the errors? How do I close the quickfix 'window'? How do I get it to check for errors after I've made changes to my code?

I've looked at the vim quickfix docs but the amount of commands are overwhelming and I can't seem to find what I want. Any help would be appreciated.

A side question: is there any way to have javascriptlint check for js errors for code residing in a .html file?

Thanks!

+4  A: 

There are a lot of commands for quickfix as you have said, but I tend to find I only use a small subset of them:

:copen " Open the quickfix window if it isn't there already (some people prefer :cw)
:ccl   " Close it
:cn    " Go to the next error in the window
:cnf   " Go to the first error in the next file

I tend to use this with :make and :vimgrep, so I can't comment on the Javascript lint checker, but this should give you something to get started.

Regarding the general use of JavascriptLint, I'm not a javascript programmer, but it looks like the script exposes a function called "JavascriptLint", so if you want to call it manually, you can use :call JavascriptLint(). However, it works on the disk copy of the file, so it'll have to be saved first. If (and only if) the command line jsl works on html files, you should be able to use :call JavascriptLint() on an html file to check the internal javascript. You could also do:

autocmd BufWritePost,FileWritePost *.html call JavascriptLint()

to automate it. If jsl doesn't support html files, then (short of patching the application or asking the author to change it), it's probably a lost cause...

Al
Thanks, those commands are a good start, I'll just have to play around a bit and get used to how it works.If I use :cn to go to an error in the qf window, can I jump to the window with my code without exiting the qf window? Can it jump to the line that has an error?And your suggestion of using :call works, however it follows <script src> links which isn't what I want.
hora
@hora: `:cn` shouldn't close the qf window, but it will switch to the window containing the error: is this what you mean by "jump"? You can quickly switch back with `Ctrl-W p` or `:wincmd p`, so you could do `:command! CN :cn | wincmd p<CR>` or something like that (untested). This should give you a `:CN` command that goes to the next error without switching out of the quickfix window. Alternatively you could do something like `:au BufWinEnter quickfix nmap <buffer> <Enter> :.cc | wincmd p<CR>` (again untested) and use Enter to select an error without switching out of the quickfix window.
Al
+1  A: 

the quickfix window is operated mostly like any other vim window: j down a line, k up a line, :cn to jump to the next error/warning, etc.

experiment!

just somebody
+1 for experimentation, that's pretty much how I learned everything.
hora
+1  A: 

You can also use :cc 2 (or any other number) to jump to, in this case, the second error in the quickfix window. Navigating with :cn, :cc 4, etc will put the cursor on the line in question.

Andy Stewart