You're using vim. You've got a tool to do this built in.
Predictably, there are seven answers already saying to use
grep. But I seem to be the only person thus far who has noticed from your question that you are using
vim. As such, although you can use
grep from within
vim, you can also use
vim's built-in tool. This is invoked via the
To search "all of the C source files in the current directory for calls to the function
toUpperCase()" one types the
:vimgrep "\<toUpperCase\_s*(" *.c
The resulting list of matches is automatically loaded up into the quickfix list, accessible with either of (see the on-line help for the subtle difference)
To find the function definition, rather than calls to it,
ctags is the tool, as mentioned in
Gilles's answer, in conjunction with the
The on-line help (
:help grep) enmumerates several of the reasons, which I won't parrot here. Further to those, compare the action of
:vimgrep with that of
dietbuddha's command line forks an individual
grep process for each individual C source file. It doesn't even employ
xargs to reduce that overhead. And you still have to somehow parse the output to invoke your text editor on the relevant source files once it is finished.
:vimgrep doesn't fork off multiple additional processes at all, and using the result is simplicity itself. Merely selecting one of the entries in the resultant quickfix list automatically positions the cursor on the relevant line of the relevant source file.
In fact, it does exactly what you wrote you would do by hand, except automatically. It's the automated way of doing those very text editor actions. It loads up the file as if loaded by hand, searches it for a regular expression (using the same regular expression syntax that you are already using elsewhere in
vim), records the places where matches occur, and then unloads the file.