I have a few really long lines of text that I'd basically like to hard wrap (break) at word boundaries before or on the 80 character mark. However, I also need to prepend characters to each newly broken line, like so:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque viverra euismod pulvinar. Fusce quis nibh commodo, commodo massa eu, ultricies nisi. Phasellus ac nulla odio.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque viverra
\ euismod pulvinar. Fusce quis nibh commodo, commodo massa eu, ultricies
\ nisi. Phasellus ac nulla odio.
I've found many methods to break long lines, but none that I've been able to modify to generate output like the above, and I can't simply tack it on after the fact because that would expand the lines beyond 80 characters again.
Can anyone recommend a Vim-compatible regex or native commands to do the above formatting? Something using sed or fmt or other external tools also welcome, but something I can use within Vim would be preferred in this case.
What I've found and tried so far:
- regex to break lines at exactly 80 characters in Vim, or the first space after - very close, but I can't figure out how to add a condition to break on word boundaries before or on 80 characters
- native Vim formatting commands, fmt, fold, etc. - all great suggestions on hard wrapping at 80 characters, but doesn't seem possible to modify to prepend the needed characters
- notepadd++-style regex to hard wrap at 80 characters - this would probably suit my needs, but can't figure out how to modify that regex to be Vim-compatible
- C# regex essentially doing the same, but again, I can't figure figure out how to modify for Vim use
I'm sure there's something fairly simple I'm missing, but stuck on how to do that conditional format to break at essentially the last space before 80 characters. Any suggestions would be very much appreciated. Thanks.