In the buffer
Before:
Release notes for 2.4
^
Fixed the retry loop.
After typing yyp to duplicate the heading line, then Vr=:
Release notes for 2.4
=====================
^
Fixed the retry loop.
The copy of the title becomes a row of 21 equals signs, one for each character in the title. The cursor sits at the start of the new underline.
When you would reach for it
You are writing a README in reStructuredText or setext-style Markdown, and every heading needs an underline that matches its length. Holding down = and counting is how you end up one short, and RST complains when an underline is shorter than its title. Duplicating the title and overwriting every character of the copy gets the length right by construction. The same move works any time you need to blank out or mask a stretch of text without changing its width.
Gotchas
rreplaces characters, not screen columns. A tab counts as one character, soName<Tab>Valuebecomes ten=signs even though it looks thirteen columns wide. Run:retabfirst if the title contains tabs.- Wide characters such as CJK text take two columns on screen but count as one character, so the underline comes out visibly short. Pad it by hand with
A=or5A=<Esc>. - Linewise
Vselects the whole line, including leading indentation. If the heading is indented, the indentation turns into=too. Use^v$instead, which starts the selection at the first non-blank character. Vrdoes not touch line breaks, so selecting several lines withVjand pressingr-gives you several lines of dashes, not one long one. That is usually what you want, but it means you cannot use it to join lines.
Variants
password=hunter2, user=admin
^
password=*******, user=admin
^
vt,r*: select up to the comma and mask it. Characterwise selection lets you overwrite a value in place without changing the line’s length, handy before pasting a config into a bug report.
id name
01 alpha
^
02 beta
03 gamma
id name
XX alpha
^
XX beta
XX gamma
<C-v>jjlrX: blockwise selection overwrites a rectangle, in this case the first two columns of three rows.
Release notes for 2.4
Release notes for 2.4
^
Release notes for 2.4
=====================
^
:s/./=/g: the Ex way to do the same overwrite on the current line. It works in vi, which has no visual mode, and accepts a range like :.,+2s/./=/g for several lines.