How do you use vim's quickfix feature?

前端 未结 8 1162
清酒与你
清酒与你 2020-12-22 15:20

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, whic

相关标签:
8条回答
  • 2020-12-22 15:39

    The easiest way to navigate the quickfix list (or the location list, for that matter) is the unimpaired plugin.

    Once the quickfix window is populated, [q and ]q go forward and back (respectively) in the quickfix list. [Q and ]Q go to the beginning and end (which is especially handy if you only have one item in the list; this makes vim complain about [q and ]q). So the workflow is:

    1. Run whatever command populates the quickfix list
    2. Type [Q to go to the first item
    3. Scroll through subsequent items (if any) with [q and ]q

    If you're using Syntastic, you'll get the location list instead of the quickfix list. No problem; just use [L, ]L, [l, and ]l in the same way.

    unimpaired has loads of other handy mappings too -- [e and ]e "bubble" lines up and down, [<Space> and ]<Space> insert blank lines above and below, etc. I was surprised nobody mentioned it here before; that's probably because it didn't exist until January 2010, though the question was asked in 2009.

    0 讨论(0)
  • 2020-12-22 15:39

    Put the following two lines in your .vimrc file:

    map <C-j> :cn<CR>
    map <C-k> :cp<CR>
    

    Now you can navigate through the errors using ctrl-j and ctrl-k, which mimics the standard down and up motion commands j and k.

    0 讨论(0)
  • 2020-12-22 15:42

    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
    :ccl   " Close it
    :cw    " Open it if there are "errors", close it otherwise (some people prefer this)
    :cn    " Go to the next error in the window
    :cp    " Go to the previous error in the window
    :cnf   " Go to the first error in the next file
    :.cc   " Go to error under cursor (if cursor is in quickfix window)
    

    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...

    0 讨论(0)
  • 2020-12-22 15:42

    Maybe this option didn't exist when this question was written (or maybe I'm embarrassing myself because there's something in my .vimrc that makes this happen) but when I get a Quickfix List, I just navigate it with j and k then hit <CR> (i.e. the Enter key) to jump to that place in the file.

    Then, to get back to the Quickfix List I type Ctrl+W j for "move down a window" and I'm back.

    Finally, when I'm done, I just type :q, like I would to close any normal window.

    0 讨论(0)
  • 2020-12-22 15:48

    In addition to @DrAl great answer about how to open and close the quick window and navigate between entries, I made an image toshow some of the other quick fix navigation commands.

    Each group of 3 files below represents a set of quickfix results, e.g. from a vimgrep. cnewer and colder are for going through historic result sets.

    0 讨论(0)
  • 2020-12-22 15:57

    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.

    0 讨论(0)
提交回复
热议问题