Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write char in line as many times as the length of previous line

Tags:

vim

I would like to write a char as many times as the length of the previous line

Starting point:

This is a line and I want to write a char under it.

I want to write char = as many times as the length of this line. This is the result I would like to obtain:

This is a line and I want to write a char under it.
===================================================

How I can achieve this result with the most reduced key/commands combination?

like image 223
aturegano Avatar asked Sep 11 '25 22:09

aturegano


1 Answers

I suspect there is something shorter but the following works with the cursor starting over the initial line:

Yp:s/./=/g

It duplicates the line (Yp), then replaces each character on the new line with an = (:s/./=/g)

Update

An even shorter version from Doktor OSwaldo

YpVr=

Duplicates the line, selects it and replaces all characters with =

And, if you are using this a lot, it'll be even shorter as a macro.

like image 127
Scroog1 Avatar answered Sep 14 '25 19:09

Scroog1