How to replace a word with all files in a folder in Vim?

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

(actually replacing a lot of words as follows: padding-bottom: 5px;)

+7
vim
source share
3 answers

Open Vim with all the files loaded into the buffers and replace on all buffers at the same time with bufdo:

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

| w | w will write each file back to disk.

+8
source share

you can try greplace.vim , which can give you a buffer, including all lines matching a given regular expression, for several files, then you can change things in the buffer and then call another greplace command so that all changes are updated for all these files .

0
source share

Hope this would be helpful for those working without vim

 find /your_path/to/folder -type f -exec sed -i 's/text_to_be_replaced/new_text/g' {} \;
find /your_path/to/folder -type f -exec sed -i 's/text_to_be_replaced/new_text/g' {} \; 

This code replaces all occurrences of text in the specified path (/ your_path / to / folder). Thought it might be useful to someone.

0
source share

All Articles