Search code examples
vim

How do I draw line in 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


Solution

  • 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 "v" typed as a control character; that is, typing "v" while holding the CTRL key down. The case of "v" does not matter; thus CTRL-V and CTRL-v are equivalent. But on some terminals, using the SHIFT key will produce another code, don't use it then. Source: Vim documentation: intro / notation / CTRL-{char}
    • 20j: moves you down 20 lines (adjust to taste)
    • r|: replaces the selection with bars