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

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?

  • 1
    I think the reason is the a flag in formatoptions, which tells Vim to automatically reformat a paragraph after text is inserted or deleted. Apparently, Vim sees that vipJ 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 executing vipJ. – garyjohn Dec 23 '15 at 18:56
  • Thanks for that, @garyjohn. I wound up adding the following function to my vimrc to help prepare text for pasting into a web form or word processor: func! PastePrepare() > setlocal fo-=a > execute "normal vipJ" > endfu > com! PP call PastePrepare() – Eirik S. Feb 11 '16 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.