vimtricks.wiki Concise Vim tricks, one at a time.

How do I navigate compiler errors, grep results, or search matches using the quickfix list?

Answer

:copen / :cnext / :cprev

Explanation

The quickfix list is Vim's built-in mechanism for navigating a list of file locations — compiler errors, grep results, search matches, or any structured output. Once populated, you can step through entries one by one, jumping directly to the relevant file and line number without manually opening files or searching.

How it works

  • Many commands populate the quickfix list automatically: :make, :vimgrep, :grep, :helpgrep
  • :copen opens the quickfix window at the bottom of the screen, showing all entries
  • :cnext (or :cn) jumps to the next entry in the list
  • :cprev (or :cp) jumps to the previous entry
  • :cfirst and :clast jump to the first and last entries
  • Press <CR> on any line in the quickfix window to jump directly to that location

Example

After running :vimgrep /TODO/ **/*.js, the quickfix list contains every TODO across your JavaScript files:

src/app.js|15| // TODO: handle edge case
src/utils.js|42| // TODO: add validation
tests/main.js|7| // TODO: write more tests

Type :copen to see the list. Press :cn to jump to the next TODO, fix it, then :cn again to move on. Use :cp if you need to go back.

Tips

  • Map quickfix navigation for speed in your vimrc:
nnoremap ]q :cnext<CR>
nnoremap [q :cprev<CR>
  • Use :cdo s/old/new/g | update to run a substitution on every line in the quickfix list and save
  • Use :cfdo %s/old/new/g | update to run it on every file in the quickfix list instead
  • :colder and :cnewer navigate between previous quickfix lists — Vim remembers up to 10 lists
  • The location list (:lopen, :lnext, :lprev) is a per-window version of the quickfix list, useful when you need multiple independent lists
  • Use :cc N to jump directly to entry number N in the quickfix list
  • :cclose closes the quickfix window when you're done
  • The quickfix list works with external tools too: set makeprg and errorformat to parse output from any build tool or linter

Next

How do I edit multiple lines at once using multiple cursors in Vim?