Search code examples
listsearchvimreplacebuffer

vim: How to search/replace in all opened files?


If I use :vimgrep, it searches all files under current directory. But my requirement is to search/replace among all opened files.

E.g. I'm using vim to open 3 files at the same time

vim 1.cpp 2.cpp 3.cpp

I wish to:

  1. search all functions called "main" and display in quickfix window, among all 3 files.

  2. Replace all "hello" with "world" in all 3 files.


Solution

  • Use the command :

    bufdo %s/string/replacement/g 

    bufdo : action on all buffers .
    s : replacing
    g : globally .