To delete some lines of text when you don't know exact number of lines to delete, you try 10dd
, 5dd
, 3dd
until you remove all the lines.
Relative line numbers solves this problem, suppose we have a file containing :
sometimes, you see a block of
text. You want to remove
it but you
cannot directly get the
exact number of
lines to delete
so you try
10d , 5d
3d until
you
remove all the block.
Enter NORMAL mode: Esc
Now, execute :set relativenumber
. Once done the file will be displayed as:
3 sometimes, you see a block of 2 text. You want to remove 1 it but you 0 cannot directly get the 1 exact number of 2 lines to delete 3 so you try 4 10d , 5d 5 3d until 6 you 7 remove all the block.
where 0
is the line number for the current line and it also shows the real line number in front of relative number, so now you don't have to estimate the numbers of lines from the current line to cut or delete or worse count them one by one.
You can now execute your usual command like 6dd
and you are sure about the number of lines.
You can also use the short form of the same command :set rnu
to turn on relative numbers and :set nornu
to turn off the same.
If you also :set number
or have :set number
already on, you'll get the line number of the line in which the cursor is at.
3 sometimes, you see a block of 2 text. You want to remove 1 it but you 4 cannot directly get the 1 exact number of 2 lines to delete 3 so you try 4 10d , 5d 5 3d until 6 you 7 remove all the block.