Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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

share|improve this question
up vote 10 down vote accepted

same effect as 3dd but upwards.

share|improve this answer
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
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

Your Answer


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.