Match and replace line breaks in vim
Published on
There are 2 different special characters when dealing with line breaks:
\n
represents the new line character byte0x0a
\r
represents the carriage return byte0x0d
But in vim at the replacement side of the pattern things change a bit:
\n
becomes the null character0x00
\r
becomes the new line character0x0a
So at the search side you should use \n
while at replace \r
.
Example:
%s/\n/\r/g
This work is licensed under a Creative Commons Attribuition-ShareAlike 4.0 International License .