1

Does anyone one know of a short key sequence that would do the equivalent of :1,-d:+,$d? Yes, I know you can define a function, macro, and that would be nice. But, maybe a bit more elegant if you could hit some predefined keys, letters, controls, and get the same result.

1
  • 1
    not exactly short... yyggdG"0P on the line you want to preserve.. however that leaves a extra empty line.. you could also do :1,-d | +,$d for single command line execution instead of two
    – Sundeep
    Commented Aug 25, 2016 at 10:22

1 Answer 1

8

Maybe this will do:

:v/\%#/d

That should deal with corner cases like the line you want to keep being the first line in the buffer, etc.

Or perhaps :move the current line to the beginning of the buffer and delete the rest:

:m0|+,$d

or:

YggPjdG

To repeat later, either map it to a key, or maybe grab it from your history with :v<up> for example.

References:
:help :v
:help /\%#

1
  • 1
    Some more: :.w!|e! and YggVGp Commented Aug 25, 2016 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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