Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm editing a paragraph in a existing HTML file remotely, and it has proper indentation (by Emacs' html-mode standards) and hard line breaks where lines would exceed 80 chars or so. Like this:

    Aaaaaaaaaaaaaa bbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc dd
    eeeeeeeeeeeee ffffffffffffff gggggggggggggggggggggggggggggggg eee

I need to rewrite, say, half of the text in the paragraph, which keeping the style intact. In Emacs, I can edit the text without worrying about indentation and linebreaks, and then press one key combination, M-q, that would call fill-paragraph and put line breaks and indentation in proper places (or I can use this key combination during editing, if I'm feeling extra tidy).

Is there a way to do something similar in Vim?

share|improve this question
up vote 1 down vote accepted

First, :setl textwidth=80. After editing the text, select the edited lines in visual mode (e.g. Vjjj), then re-indent with =. Finally, re-establish the selection and re-format: gvgq.

share|improve this answer
Thanks, that helps. If I'm not careful with selection, gq pushes several tags together on the same line, but looks like this is the best option anyway. – dgutov Feb 23 '13 at 23:20
:set textwidth=80

Will set the line limit to 80. This article explains how to link a HTML tidy program into vim:

share|improve this answer
What if it's on a remote machine, one I don't have much access to? Otherwise I would just use Emacs. – dgutov Feb 23 '13 at 5:37
Could you give me the best approximation using Vim's built-in features? – dgutov Feb 23 '13 at 5:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .