Reputation: 3178
I have a long line of characters in vim. I'd like to insert a newline after 80 characters. How do I do that?
Upvotes: 18
Views: 15242
Reputation: 496
You can also modify this approved answer to only insert the newline at the first space occurring after the 80th character:
%s/\(.\{80\}.\{-}\s\)/\1\r/g
Upvotes: 6
Reputation: 792
Using regular expression:
:%s/\(.\{80\}\)/\1\r/g
Using recursive Vim macro:
qqqqq79la<Enter><esc>@qq@q
qqq Clear contents in register q.
qq start marco in register q
79la<Enter> Carriage return after 80 characters.
<esc> go back to normal mode
@q run macro q which we are about to create now.
q complete recording macro
@q run macro
Upvotes: 6
Reputation: 3178
:%s/.\{80}/&\r/g
Upvotes: 29