Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 394
Hind Forsum Avatar asked Mar 04 '26 05:03

Hind Forsum


1 Answers

Use the command :

bufdo %s/string/replacement/g 

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

like image 100
Ziyadsk Avatar answered Mar 07 '26 03:03

Ziyadsk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!