You could use Vim's grep command to search all the files in your project:
:grep! "\<<cword>\>" . -r
Let's put that in a keybind:
nnoremap <F4> :grep! "\<<cword>\>" . -r<CR>:copen<CR>
I find this one-key project-wide search invaluable when I am exploring a large unfamiliar codebase.
\> are regexp sequences which indicate the start and end of a word, so you won't get partial matches. (The
-w option to grep might be another way to achieve this.)
However, this is an unintelligent search, so it can produce false-positives if the same word appears in unrelated contexts.
Truthfully, I use my own modified version of the grep.vim plugin instead. This is slightly friendlier to use:
- It lets you edit the search pattern, and also the grep commandline (so you can target specific folders like
src/ lib/ instead of
.) and remembers the changes.
- I added support for Google's csearch. This can be much faster than grep (on HDDs) because it builds an index of words rather than scanning each file every time. Notably, csearch uses a slightly different regexp standard, so
\b must be used instead of
I configure it and exclude some standard files like this.
For fast access, I create two keybinds. F3 lets me edit the commandline, F4 uses the previously configured commandline without any extra keystrokes. The mechanism is pretty ugly, and could use some cleanup, but it has served me well.