Copy text file without hard-wrap new lines

Alec Jacobson

February 28, 2014

weblog/

I often format small text entries in vim and then copy them into other places like web forms. In vim I like to have a hard 80 character line wrap. But this means that after every 80 characters I have a newline character. If I just copy the file or from the terminal screen then I'll impose this hard wrap in the submitted text. I've noticed that this is especially bad for academic review submissions because the submission system might then additionally impose its own hard wrap at a different width causing a very staggered, ragged appearance.

Here's my solution to copy a text file without newlines but keeping double newlines which indicate paragraphs.

cat % | perl -pe '$/=""; s/\n([^\n])/ \1/g;' | pbcopy

There must be a way to do this inside of vim properly, but I couldn't figure it out.