I have a long line of characters in vim. I'd like to insert a newline after 80 characters. How do I do that?
A sequence of zero or more non- <newline> characters plus a terminating <newline> character. And, therefore, they all need to end with a newline character. That's why Vim always adds a newline by default (because, according to POSIX, it should always be there). It is not the only editor doing that.
To break a line without affecting text, move the cursor to a space where you want the line to break and type r (for "replace") followed by Return . Note that if you type r with the cursor on a character and then press Return, that character will be replaced by the Return.
:%s/.\{80}/&\r/g
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With