Vim Tips Wiki
Tip 517 Printable Monobook Previous Next

created 2003 · complexity intermediate · author Cameron Kerr · version 5.7

Normally, I bind F4 to gqap, which suffices nicely to rejustify plain text, and most of my latex and HTML stuff (with due care taken to have plenty of blank lines for delimiting.

However, if you're dealing with *roff style markup, such as man-pages or (in my case) documents using the -ms groff macros, it won't work, as the tags are on the line just above, such as the following example.

.IP Boggart
Magical being that transforms into whatever the viewer most fears.
Professor Lupin used a boggart to
teach Harry how to repel Dementors, as
(at that time) Harry most feared Dementors.

Ideally, I'd just position the cursor on the body of the text (this a definition list entry, if anyone is wondering), and just press F4. But that would also rejustify the argument to the IP macro, which would be bad.

So instead of using gqap, I use gq an a selected range of lines. I search upwards something that might be a macro, or a blank line, move down a line into the body, start to select, search forward for the next macro or blank line, then gq to rejustify.

The regex I use to search for the extents is


Since the document I'm working with has an extension of .groff, I bind, on BufferEnter, the following macro.

au BufEnter *.groff nmap <F4> ?\(^\.[A-Za-z]\{2\}\\|^$\)<CR>jV/\(^\.[A-Za-z]\{2\}\\|^$\)<CR>kgq