Olle Härstedt
Olle Härstedt

Reputation: 4020

How do I grep in vim netrw?

How do I do a grep in netrw in Vim? ctrl-p can be used in this way, is there a similar plugin for grep?

E.g., when I'm in a directory, I want a list of files containing this or that keyword.

Upvotes: 3

Views: 2244

Answers (2)

user21497
user21497

Reputation: 1181

Netrw does have "that feature"; see :help netrw-star. You can do for instance :Explore */filepath or more generally use one of the patterns below:

*/filepath   files in current directory which satisfy filepath
**/filepath  files in current directory or below which satisfy the
            file pattern
*//pattern  files in the current directory which contain the
            pattern (vimgrep is used)
**//pattern files in the current directory or below which contain
            the pattern (vimgrep is used)

Use :Pexplore and :Nexplore to go to the previous/next matching file (and @: to repeat the chosen command); hit <cr> to enter the file.

Upvotes: 7

romainl
romainl

Reputation: 196456

Netrw doesn't have that feature.

You can use the built-in :vimgrep:

:vim foo * | cw

or :grep, that uses your external grep by default or whatever alternative program (like ack or ag) via the grepprg option:

:grep foo * | cw

See :help :grep, :help :vimgrep and :help :cwindow.

Upvotes: 2

Related Questions