December 9

HTML Paragraph-ize in Vim

:100,150 s/\s*(\S.*\S)\s*/<p>\1<\/p>/

A little vim command to surround lines in <p> tags. It says to take lines 100 to 150, strip whitespace at the start and end of the line and then add the opening and closing tags.

You should change the line numbers to fit your situation. If you want it to apply to the whole file, replace the 100,150 with %.

It leaves empty lines or lines with only whitespace alone. It also ignores lines with only one non-whitespace character, which might be considered a bug, but I didn’t have any of those.