3

I write comments of the form

#############
## Example ##
#############

Always one line, always just like that. It's a way of breaking up code more visually. I have lately taken to the following way of typing them out:

  1. Type double #, space, the comment, space, double #.
  2. Look at the ruler in right hand corner for the horizontal position.
  3. <esc>ki#<esc><the_number_from_step_2_minus_one>.<esc>yyjp to enter n #'s, yank it, and paste it at the bottom.

But even this seems redundant. I would like to define a macro of the form:

:let @a='k<n>#i<esc><esc>yyjp<esc>'

Where <n> is the length of the line I will execute the macro on:

## Example ##

But I do not know how to record and store the position of the last character on the particular line. Suggestions?

I have found this suggestion from the vim wikia but I don't want a plugin, and this from Stack Overflow but this seems like overkill again.

Note: I don't use any plugins and would prefer not to. I literally have none. And a fairly short vimrc (<50 lines after a recent doubling).

1 Answer 1

5

You don’t need to know the length of the line. This ought to do it:

:let @a = 'yyPVr#jpVr#'

I’d also automate the adding of the hashes at the start and end of the middle line:

:let @a = "I## \<Esc>A ##\<Esc>yyPVr#jpVr#"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.