use vi editor to insert newline char in replace

Something else I have to do and cannot remember and then have to look up.

In vi to insert a newline character in a search and replace, do the following:

:%s/look_for/replace_with^M/g

the command above would replace all instances of “look_for” with “replace_with\n” (with \n meaning newline)

to get the “^M”, enter the key combination “ctl-V” then after that (release all keys) press the “enter” key.

Unknown's avatarAbout Jayson
Father, mountain biker, Software development manager at a wire service, and also work with the IPTC (iptc.org)

2 Responses to use vi editor to insert newline char in replace

  1. cellurlj's avatar cellurlj says:

    thanks. You beat stackexchange…. 😉

    Yours worked. (I could never remember how to do control-capital-V thing.

Leave a comment

Design a site like this with WordPress.com
Get started