2

This isn't a particularly important, but it's something I've been curious about for a while.

I write a lot of documentation using rST (Sphinx). This is how you write a heading:

My Awesome Heading
==================

Lorem ipsum dolor...

I'm wondering if there's a clever way in vim to do that underline, rather than just rapidly pressing the equals key a dozen times.

6
" underline current line
yypVr=
1
  • A bit shorter: the default behavior for Y is the same as yy.
    – pandubear
    Dec 28 '13 at 7:21
4
:t.|s/./=/g

One keypress shorter than Barton's solution. ;)

2
  • thx, this is going to my vimrc.
    – amdorra
    Dec 23 '13 at 4:26
  • Shifting is a keypress. You tied. :)
    – codelahoma
    Dec 28 '13 at 21:21
2

Try

yyp
:s/./=/g

This copies and pastes the current line, then substitutes '=' for each character.

You can wrap this a macro or set up a function within .vimrc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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