Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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: http://vim.wikia.com/wiki/Cleanup_your_HTML

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.