Vim - surround comment line with comment character
11 8 7 keystrokes
YpVkr#p
Yp - duplicate current line, leaving the cursor at the lower of the two
V - enter visual line mode
k - go up and select both lines
r# - replace every selected character with #. Leaves visual mode and leaves cursor at the upper line.
p - put the yanked line (the original) on the next line.
(thanks to doorknob for reminding Y=yy)
16 15 14 keystrokes
Yp
:s/./#/g
<cr>
YkP
The straight-forward approach: duplicate the line, replace all characters with #
, copy the the result and paste it above.
I'm counting P
and :
as one keystroke each (instead of two for Shift+p or Shift+;). That being said, the question specifies to count "commands", where I'm not sure how to count the substitution.