Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Find and replace in a large project?

Tags:

replace

vim

There's a way to replace all occurencies of a string in files in Vim using a combination of args and argdo commands. Unfortunately there's a drawback with this solution: It will open all files which may be a problem for large projects. Does anyone know more compact and memory efficient way?

like image 290
nab Avatar asked Mar 02 '12 22:03

nab


2 Answers

find projectfolder -type f -exec grep -Iq 'pattern' {} \; -exec vim {} +
like image 183
Kevin Avatar answered Oct 20 '22 01:10

Kevin


Here's how I do it (when I'm not using perl):

find . -name '*.java' -exec vim +'%s/OldName/NewName/gc' +'wq' {} \;

i.e. replace "OldName" with "NewName" in all "*.java" files, but prompt me for confirmation for each substitution.

like image 24
Manish Avatar answered Oct 19 '22 23:10

Manish