Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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
share|improve this answer
    
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 '10 at 9:08

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.