You can use the global and substitute commands (:help :g, :help :s) to underline all headings matching a pattern. For example, the following adds a row of dashes under each line that starts with "Chapter":

:g/^Chapter/t.|s/./-/g

It works by finding each matching line, then copying it (:help :t), then substituting each character (.) in the line.

yypVr- also works well. Great tip for Markdown and WikiTex users.
Linktohack 15:37, February 3, 2012 (UTC)

Thanks. There is a subtle feature about the method in the tip. If you have the default 'virtualedit' setting (""), and if there is a tab in the line, using Vr- replaces each tab with a single dash, while the method in the tip uses the correct number of dashes depending on the width of the tab. JohnBeckett 06:50, February 4, 2012 (UTC)