I normally do a find -type f | xargs grep 'something' and try to open those files in the Vim. What is happening is, I have to close and open Vim sessions and sometimes, I have to do the find operation again, if I had lost the result. Is there a way to automate this in Vim, like I would like the Vim to open all these files into separate buffers so that I can switch between them seamlessly? Note that I am looking if I can execute these find commands from within Vim (using !) and then load those files as buffers.
Any other tricks you would use, if you are in for above situation?
Vim has several commands integrating and implementing Grep capabilities (see
:help grep). The two major ones are:grepand:vimgrep. The formeruses external Grep program (set by
grepprgoption), while the latter usescore Grep functionality implemented in Vim itself.
The main advantages of the internal
:vimgrepare Vim regex syntax andportability, that includes
**glob wildcard. The:vimgrepcommandunderstands a subset of extended glob patterns (see
:help wildcard). Thisallows to avoid
findcommand in most of the cases. Using:vimgrep, yourexample search would look like the following.
The same search can be performed with
:grepcommand, if your shell orgrepprgimplements the**wildcard. Below is an example showing Zshextendned glob notation.
Both of these commands (and their variants) utilize Vim interface features
called QuickFix list and its window-local version, location list (see
:help). The QuickFix window is a special read-only buffer containing anyquickfix
kind of search results relating one or several files. Search results
collected by Grep commands are immediately aggregated in the QuickFix window.
The QuickFix list represents each matching position of the search pattern by
a single line, and allows to quickly switch between them by pressing
Enter on these lines. There is not a few commands related to the
QuickFix list. Here I list only some of them as a starting point (see help
for additional information).
:cwor:copeopen the QuickFix window (see help to understand thedifference between them).
:cc,:cn,:cpdisplay the current, the next, and the previousmatch in the list, respectively.
:cr,:cladisplay the first, and the last match in the list,respectively.
:cclcloses the QuickFix window.A location list is a QuickFix list attached to a certain window. Each window
can have a single location list attached to it (independent from other
windows’ location lists and the QuickFix list). Any QuickFix list command
of those listed above has an equivalent working with a location list.
:lwor:lopopen the location list associated with the currentwindow.
:ll,:lne,:lpdisplay the current, the next, and the previousmatch in the list, respectively.
:lr,:lladisplay the first, and the last match in the list,respectively.
:lclcloses the location list.Location list counterparts of the
:grepand:vimgrepcommands are:lgrepand
:lvimgrep, respectively.