views:

90

answers:

2

I'm reading through a large C++ code base in Vim.

Within a single file, I can do

/foo
n
n
n

Now, if I want to search through more than one file, I have to do:

:vimgrep /foo/
:cn
:cn
:cn

Now, typing ":cn" is so much less convenient than "n". Is there a way to search through vimgrep results with "n" (like searches with /) instead of ":cn"?

Thanks!

+3  A: 

This is what I have in my .vimrc exactly for this purpose:

nmap <F7> :cp^M
nmap <F8> :cn^M
Michael Krelin - hacker
+1 for the mapping...I use `noremap <F4> :<C-U>cnext <CR>` to do the same thing.
Johnsyweb
+3  A: 

Use the Quickfix List. It will automatically be filled with found matches (no matter if you use :grep or :vimgrep). It can be navigated with the usual keys (so the key for "next" is j instead of n).

To open it use :copen.

honk