## Copy lines without cursor movement
Your cursor is on line 10. You want to paste line 20 to one line below your current cursor
position. Here’s how to do that using
You can also use ranges. Let’s say your cursor is on line 10. You want to paste text from line 20
to 25 under line 10. Here’s how:
It gets even better:
:t is an alias of the
co[py] command, so you could save some keystrokes.
You could run the commands from above and achieve the same result if you’d replace
This command works with relative line numbers as well. For example, to paste the line, which
is 10 lines above your current line, to a line below your current position:
One last example: if you’re at line 45,
:35,t. will make a duplicate of lines 35 to your cursor
(that is, from 35 to 45 inclusive) and put it after your current cursor.
So, imagine this case: you have a function and your cursor is one line below it. You also have
relative line numbers enabled. You see that the function starts 15 lines above your current line.
To make a copy of the entire function and place it after your current line, you could run:
## Move lines without cursor movement (that much)
The usage of command
m[ove] is similar to
co[py] command. For example, to move a line 6 to
line 28, you’d run:
It also supports ranges and relative lines.
Here’s an example using both:
This command would take five lines which are located between lines 10 and 5 above your current position, and move them to 7th line under your current position.
After this command, the position of your cursor will change. In order to come back to the original location where your cursor was before running this command, simply hit
Surely, the cursor moves. But, this workflow saves you from moving your cursor around to perform the visual selection.
## Delete lines without cursor movement (that much)
Wouldn’t it be cool to be able to delete lines without moving your cursor?
:m[ove] commands, you can also run
:d[elete] command to delete lines without jumping to those lines.
For example, to delete lines 5 to 10, run:
However, this command would leave the cursor at the deleted line location, so you’d need to use
'' to jump back to the previous position.