I have decided to use Vim for editing prose, as I find it to be a much more work-conducive, clutter-free environment than most so-called text processors expressly built for that purpose. To that end, and on the advice of some internet stranger with a blog, I added this function to my vimrc to quickly enable (and disable, I suppose? I don't really know how to tell whether the function has been turned off again) a prose-editing mode which sets a text width and text-wrapping options that make sense for natural languages:
func! WordProcessorMode()
setlocal formatoptions=ant
setlocal textwidth=72
setlocal wrapmargin=0
endfu
com! WP call WordProcessorMode()
However - as has already been adressed in this post: https://stackoverflow.com/questions/11039544/unwrap-text-in-vim - sometimes I would like to unwrap that text in order to paste it into a forum post (as I'm doing right now) or an e-mail editor, or whatever. When I try to vipJ
under this custom word-wrapping mode, though, nothing happens. Why is that?
a
flag informatoptions
, which tells Vim to automatically reformat a paragraph after text is inserted or deleted. Apparently, Vim sees thatvipJ
as having inserted and/or deleted text, so it reformats the paragraph, restoring the original line breaks. One way to fix the problem is to execute:setlocal fo-=a
before executingvipJ
.