Great tools to find and replace in files? [closed] Great tools to find and replace in files? [closed] linux linux

Great tools to find and replace in files? [closed]


Try sed. For example:

sed -i -e 's/foo/bar/g' myfile.txt


Vim has multi-file search built in using the command :vimgrep (or :grep to use an external grep program - this is the only option prior to Vim 7).

:vimgrep will search through files for a regex and load a list of matches into a buffer - you can then either navigate the list of results visually in the buffer or with the :cnext and :cprev commands. It also supports searching through directory trees with the ** wildcard. e.g.

:vimgrep "^Foo.*Bar" **/*.txt

to search for lines starting with Foo and containing Bar in any .txt file under the current directory.

:vimgrep uses the 'quickfix' buffer to store its results. There is also :lvimgrep which uses a local buffer that is specific to the window you are using.

Vim does not support multi-file replace out of the box, but there are plugins that will do that too on vim.org.


I don't get why you can't do this with VIM.

Just Find

/Foo

Highlights all instances of Foo in the file and you can do what you want.

Blindly Replace

:% s/Foo/Bar/g

Obviously this is just the tip of the iceberg. You have lots of flexibility of the scope of your search and full regex support for your term. It might not work exactly like your former editor, but I think your original 'use one editor' idea is a valid one.