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
    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
    Aug 25, 2016 at 10:22

1 Answer 1


Maybe this will do:


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:




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

:help :v
:help /\%#

  • 1
    Some more: :.w!|e! and YggVGp 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.