Alex Shroyer
Alex Shroyer

Reputation: 3829

Insert characters to end of previous line in Vim

I like the Markdown style underlining, but I want it to line up with the above line.

So for example if I have this:

heading one
_
^ cursor here

I could (in normal mode) just type (something)i=<ESC><ESC>, and the result would be:

heading one
===========
          ^ cursor here

Does anyone know what I can use for (something)?

It doesn't really matter to me where my cursor is/ends up, so for example I could be on the last position of the heading one line and do some operation to achieve the same result. I'm picky, but not that picky.

Upvotes: 1

Views: 113

Answers (2)

romainl
romainl

Reputation: 196691

kyypv$r=j
  • go up one line
  • yank it
  • paste it below
  • visually select the line
  • replace every character with =

Turn it into a mapping if you ned it often:

nnoremap <key> kyypv$r=j

I'd suggest you do this on the line to underline itself and not on the line below, though:

nnoremap <key> yypv$r=

Upvotes: 2

FDinoff
FDinoff

Reputation: 31439

If you use visual selections you can then use r to replace every character in said visual selection.

So if you start with your cursor on the "heading one" line type.

yypVr=

Would copy the line and then replace every character with an equal sign.

Upvotes: 3

Related Questions