1

I changed my Caps Lock key to Ctrl, and as I'm still getting used to it I sometimes enter combinations I didn't intend to.

While in insert mode typing, having already written most of a long sentence, I accidentally pressed Ctrl-U, which deleted all the characters I had typed so far.

Is there any way to undo this and get those characters back, without retyping them?

3

You can't recover the words you've already lost, but we can make <c-u> an undo-able motion by remapping it:

inoremap <c-u> <c-g>u<c-u>

This is from vim-sensible. See :h i_CTRL-G_u; essentially, the <c-g>u causes vim to 'break' the change at that point, meaning you can undo back to that point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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