Tuesday, September 07, 2010

vim vs. grep : external quickfix/error file, cont'd

As an enhancement to my old trick of using grep with the VIM, I have finally come up with a solution which doesn't use the temp file:

$ alias vq="vi -c ':cgetb' -c ':cfirst! ' -"
$ grep -nr whatever . | grep -v garbage | vq


The trick is to use the new VIM 7.x command :cgetb which retrieves the error list from the current buffer. So first suck in the output of the grep into the nameless buffer, tell VIM to use the buffer as a error list and then with :cfirst! to jump to first matching line (and discard the nameless buffer).

Note in alias the space after :cfirst!: it is a secret ingredient to avoid bash interpreting the ! as the history expansion mark.