Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I replace a word all the files within a folder in Vim?

Tags:

vim

I know that by typing the following: :%s/iwanthis/replacedbythis/g will change all the matching words of the file. How can I do the same for all the files within a folder?

(actually replacing a lot of words like this: padding-bottom:5px;)

like image 665
alexchenco Avatar asked Apr 17 '10 07:04

alexchenco


1 Answers

Open Vim with all the files loaded into buffers, and do the replace on all buffers at once with bufdo:

% vim *
... when vim has loaded:
:bufdo %s/iwanthis/replacedbythis/g | w

The | w will write each file back to disk.

like image 122
Dave Kirby Avatar answered Nov 19 '22 15:11

Dave Kirby