How do I insert an actual newline in a substitution replacement, and why does backslash-n not work?
s/pattern/\r/
In Vim substitutions, \r in the replacement string inserts a line break, creating a new line.
s/pattern/\r/
In Vim substitutions, \r in the replacement string inserts a line break, creating a new line.
\n in search, \r in replacement
Vim uses \n and \r differently depending on whether they appear in a search pattern or a replacement string, and mixing them up is a common source of confusion.
:%s/; /;\r/g
In the replacement part, use \r to insert a newline.
:%s/,/\r/g
In Vim's substitute command, \r in the replacement string inserts a newline.