---

Advanced Tips for Search-and-Replace in Linux

“Search-and-replace is likely to be the operation you’ll most
often use regexps for in an editor. First let’s look at a
straightforward non-regexp search-and-replace. Let’s say that
you’ve just decided to rename a variable from foo to fooOne. In
Vim, hit Esc for command mode, then use this command:

“:%s/foo/fooOne/g

“% means that the operation should be carried out throughout the
whole document. The important part is s/foo/fooOne/, which means
“replace every instance of ‘foo’ with ‘fooOne'”. The final g means
“global”; without this you’ll just replace the first instance on
every line, but with it, you replace every occurrence.”

Complete
Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis