How to jump between patterns when using :vimgrep (Quickfix list)?

Useful commands for the quickfix list (brackets around omittable part of the commands):

  • :cn[ext] and :cp[revious] jump to next and previous entry
  • :cnf[ile] and :cpf[ile] jump to next and previous file (if the quickfix list is not sorted by file you could write a function that getqflist(), performs a sort and then setqflist()
  • :cr[ewind] and :cla[st] go to beginning or end of the quickfix list
  • :col[der] and :cnew[er] will iterate through historical quickfix lists.

Needless to say there are plenty of other commands and you can discover them at :help quickfix.

Personally I have the following maps :

      | ΓΈ      | SHIFT   | CTRL
------+--------+---------+---------
<F11> | :cprev | :cpfile | :colder
<F12> | :cnext | :cnfile | :cnewer

Of course if you use the location list instead of the quickfix list (:lvimgrep) the same commands exist, just replace the initial c with an l and that’s it.

Vim 8 Additions:

  • :cdo : perform a command on all entries of quickfix list. For example
    :vim /foo/ *.cpp *.h *.hpp can be followed by
    :cdo s/pattern/replacement/g
  • :cfdo: perform a command an all files in quickfix list. For example,
    :vim /foo/ *.cpp *.h *.hpp can be followed by
    :cfdo %s/2ndpattern/2ndreplacement/g

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)