How to search across a directory of files in vim?

32,710

Solution 1

You can simply use the :grep command: or for a more complete integration of search tools, use the grep.vim extension.

Simply type :help grep to get a nice documentation of what is available out of the box in Vim. Using :grep foo *.?pp should do what you want. This will open the QuickFix list, just like the one you get using :make, enabling to jump to the found occurrences.

Solution 2

There is a fantastic plugin named ctrlsf.vim ,which makes you search in vim efficiently.

Here is a snapshot of it.Quite cool ,isn't it?

enter image description here

For instance , If you want search word like "hello" in current dir , after installation , all you need to do is Simply type:

:CtrlSF "hello"

then you'll get what you expect.

Have fun!

Solution 3

:help windo
:help bufdo
man find
man xargs

find ./start/point -iname "*.cpp" -print0 | xargs -0 vim
:bufdo s/baar/foo/gc
:wall
:qall

gc "global confirm", wall (write all), qall (quite all). To see file list :ls top jump to next file :wn (write next) or :bn (buffer next). By the way, xargs manage large chunks of file in memory to deliver to vim withou erros.

Share:
32,710
anon
Author by

anon

Updated on November 07, 2020

Comments

  • anon
    anon over 3 years

    A common programming task for me in vim is:

    :s/some pattern/
    

    do some work

    n # finds the next entry

    do some work

    n # finds the next entry ...

    Now, s/.... only searches in the current file.

    Is there a way I can do this, but search across a directory of files? Say do "s/..../" over all files in subdirectoires of pwd that ends in .hpp of .cpp ?

    Thanks!