I'm often editing files where i have to delete everything except the five first and the three last rows. I do that by moving to row six and type ":,.$-3 d". Is there any way accomplish the same using d and some kind of motion?

1 Answer 1


Sure is! d[num]G where [num] is the destination line number. Any other movement command will also work rather than G, of course.

To delete the first five and last three rows, assuming you've just opened the file and are on the first line, it would be:

d5G   # delete from current position to line 5
G     # jump to last line
d2k   # delete from current position to 2 lines up (3 lines total)

Edit: Just reread the question and saw I got your intentions backwards - you want to keep the first five/last three, not delete them. In that case, it's:

G     # jump to last line
3k    # up 3 lines
d6G   # delete from current position to line 6
  • Thank you for your answer. I always tried to do it the other way around, positioning myself at the sixth row trying to move(delete) to row $-3.
    – johnny
    Nov 16, 2010 at 9:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .