Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I draw line in VIM?

Tags:

vim

How do I draw a vertical line instead of typing one by one?

For example, I wanna set a vertical line in column 10 for 20 rows. Just like my first line. how do I do that in smart way?

enter image description here

like image 588
CCC Avatar asked Nov 27 '11 02:11

CCC


3 Answers

First, set virtualedit=all, to allow yourself to navigate past the end of a line:

:set virtualedit=all

Then...

10|<C-V>20jr|

Where:

  • 10|: moves you to screen column 10
  • ctrl+V: enters blockwise visual mode
  • 20j: moves you down 20 lines (adjust to taste)
  • r|: replaces the selection with bars
like image 129
Johnsyweb Avatar answered Oct 20 '22 05:10

Johnsyweb


The following is an alternative solution to setting virtualedit=all in order to make 20 rows with a | in column 10:

  1. Starting in Normal mode, make an example line, e.g. 10i<space><esc>r|
    • 10ispace will insert space ten times, and pressing esc followed by r| will replace the last character with a |
  2. Copy the entire line with Y
  3. In Normal mode, paste the copied line 20 times with 20p
    • This will paste the recently copied line 20 times below, giving you a total of 21 identical lines

In sum:

10i<space><esc>r|Y20p
like image 22
Alejandro Carrillo Avatar answered Oct 20 '22 05:10

Alejandro Carrillo


This appears to be a VIM plugin to do exactly what you are looking for:

http://www.vim.org/scripts/script.php?script_id=40

I have not tried it myself.

like image 30
MK. Avatar answered Oct 20 '22 05:10

MK.