Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

I am editing restructuredtext files. I often need to put some charactors like "=-`~" in one line, and I want the length of the line match the previous line. How should I do this in vim?

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

Thanks!

like image 917
zjk Avatar asked Aug 08 '11 06:08

zjk


People also ask

How do I add a line in vim?

Starting in normal mode, you can press O to insert a blank line before the current line, or o to insert one after. O and o ("open") also switch to insert mode so you can start typing. To add 10 empty lines below the cursor in normal mode, type 10o<Esc> or to add them above the cursor type 10O<Esc> .

How do I put multiple lines of text in vim?

vim Inserting text Insert text into multiple lines at once Press Ctrl + v to enter into visual block mode. Use ↑ / ↓ / j / k to select multiple lines. Press Shift + i and start typing what you want. After you press Esc , the text will be inserted into all the lines you selected.

How do I jump to a specific line in vi editor?

If you're already in vi, you can use the goto command. To do this, press Esc , type the line number, and then press Shift-g .


3 Answers

Another that will work:

yypv$r=
like image 91
Barry Brown Avatar answered Oct 14 '22 21:10

Barry Brown


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

You can map that to a key, e.g. :map <F5> yyp:s/./=/g<CR>

like image 22
Johan Kotlinski Avatar answered Oct 14 '22 21:10

Johan Kotlinski


I would use yypver= to avoid searching & shift button as much as possible. This could of course also be mapped to a key.

like image 2
chelmertz Avatar answered Oct 14 '22 22:10

chelmertz