Search and Replace for a New Line Character in VI

For all of you out there who use vi on a regular basis . . . I recently needed to do a search and replace on a large document and needed to key off of the new line characters in the document.

After a bit of searching here’s what I found:

If you need to do something like, search for all new lines and add the new line plus "foo" do the following:

:1,%s/\n/^Mfoo/g

You get the ^M character by pressing ctrl-v and then hitting enter.

Leave a Reply