Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

We can delete lines after the cursor (e.g.: the next 3 lines) with:

3dd

But how can we delete the lines before the cursor? (e.g.: 3 lines before cursor)?

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted
2dk

same effect as 3dd but upwards.

share|improve this answer
2  
While the '2' might sound counterintuitive you need to remember that when deleting upwards it starts with the line the cursor is on, /then/ follows the move command. This may sound weird, but it is in fact consistent with how vi handles commands. –  Shadur Mar 14 '11 at 10:31
3  
Actually, it's not just because you're deleting upwards, it's because the structure of the command is different. 'dd' means delete this line. 3dd means 'delete this line'x3. On the other hand 'dk' means 'delete from here to one line up' - that means two lines. So '2dk' means delete from here to two lines up'. By the way, you can delete downwards the same: '2dj' will also delete three lines - it's the same as '3dd'. –  Shawn J. Goff Mar 14 '11 at 12:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.