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.

About these ads

About Jayson
Father, mountain biker, Software developer 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 says:

    thanks. You beat stackexchange…. ;-)

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: