How can I put a string like "==========" quickly in vim

I am editing structured files. I often have to put some characters, such as "= -` ~" on one line, and I want the line length to match the previous line. How do I do this in vim?

a long long title ================= 

Thanks!

+6
source share
5 answers

What about yyp:s/./=/g ?

You can match this with a key, for example. :map <F5> yyp:s/./=/g<CR>

+6
source

Another one that will work:

 yypv$r= 
+17
source

I would use yypver= to avoid as many search and shift buttons as possible. Of course, this can also be mapped to a key.

+2
source

If your line starts without any trailing spaces:

 Hello World 

Normal mode:

Y p V r =

gives:

 Hello World =========== 

Explanation

Y β†’ Yankees whole line e.g. Y Y
p β†’ insert row
V β†’ select the whole line in the visual line mode r β†’ replace the whole selection with the following character
= β†’ character to replace the rest

If the string has leading spaces, for example:

  Hello World 

Using:

Y p V $ r =

Donation:

  Hello World =========== 

We use the visual selection of V $ at the end of the line, instead of using V to select everything on the line.

If you have a trailing space, you can use the g _ movement to jump to the last character without spaces.

+2
source

When the cursor is placed on a long long line , you can use something like

 :s/\(.*\)/\=submatch(1) . nr2char(13) . repeat('=', strlen(submatch(1)))/ 

To facilitate this replacement, I would use a map:

 nmap __ :s/\(.*\)/\=submatch(1) . nr2char(13) . repeat('=', strlen(submatch(1)))/ 

So, you can underline the line in which the cursor is on by typing __ .

0
source

Source: https://habr.com/ru/post/894520/


All Articles