I frequently want to select multiple lines in vi. e.g. from line 1 to line 10.
So, what I usually do when I want to jump from line to line is I type :110
to jump to line 110
, e.g.
And, when I want to select from line to line, I usually press v
to get into visual mode, and then I just scroll down using k
or l
.
So, intuitively it makes sense to me to just press v
, and then type :<line number>
. but that doesn't work.
How to select from line X to line Y in vi?
Let's assume you want to highlight from line 10 to line 20. You can use:
10GV20G
Breakdown:
10
into the buffer20
into the bufferNote that G means Shift+g (capital G
).
You can use gg instead of G.
If you want to highlight 10 lines down relative to (and including) your current line, use V9j.
Source and a :
command are here.