Vim - surround comment line with comment character Today I realised that I often like to define sections in my code like so:

####################
# Helper Functions #
####################


But that it's tedious to do. Assuming I have a line such as this:

# Helper Functions #


What is the shortest set of vim keystrokes to wrap it in a #? Shift does not count as a keystroke in this challenge.

Test cases:

Input: "#test test test#"
Output:
################
#test test test#
################

Input: "#this is a nice block comment#"
Output:
##############################
#this is a nice block comment#
##############################

Input: "# s p a c e s must be supported a l s o#"
Output:
########################################
# s p a c e s must be supported a l s o#
########################################
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)