2

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:

<body>
  <p>
    Aaaaaaaaaaaaaa bbbbbbbbbbbbbb cccccccccccccccccccccccccccccccc dd
    eeeeeeeeeeeee ffffffffffffff gggggggggggggggggggggggggggggggg eee
  <p>
</body>

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?

2 Answers 2

2

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.

1
  • 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, 2013 at 23:20
2
:set textwidth=80

Will set the line limit to 80. This article explains how to link a HTML tidy program into vim: http://vim.wikia.com/wiki/Cleanup_your_HTML

2
  • 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, 2013 at 5:37
  • Could you give me the best approximation using Vim's built-in features?
    – dgutov
    Feb 23, 2013 at 5:37

You must log in to answer this question.

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