I know this is a bit of vim-golfing, but I am interested in other opinions / ideas. Sometimes I have to edit a file and to delete all but the current line. My go to solution involves ex mode :t0|2,$d
These are as many as 8 keystrokes! (I am aware that this command can be mapped easily to some convenient combination on the keyboard.) Other suggestions, ideas?
first of all your approach is not 8 keystrokes, if we don't count the save (ZZ
), they are 9 keystrokes. Because you have to press Enter
.
There is one way, with 6 keystrokes:
YggVGp
Apart from golfing, I feel my approach is more straightforward than yours. Perhaps because I like normal mode in vim. :-)
For practice, if you need do it many times, you may want to have a mapping.
Another solution:
:.w!|e<CR>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With