« Back to Index

linefeed and carriage return

View original Gist on GitHub

Tags: #vim

vim linefeed and carriage return.md

The term CRLF refers to Carriage Return (ASCII 13, \r) Line Feed (ASCII 10, \n). They’re used to note the termination of a line, however, dealt with differently in today’s popular Operating Systems.

Imagine in vim you have a buffer like:

a
b
c
d

If you wanted to add an extra line space between each line, so it looked like:

a

b

c

d


Note: my example is based on me running Vim on macOS.

You would need to use a substitution like:

:%s/\n/\r\r/

Notice you’re looking for a ‘line feed’ \n (because that’s how macOS denotes a new line), while to get Vim to insert a line break I need it to insert two separate ‘carriage returns’ \r.