If I have vim in a windowed terminal, sometimes I paste (using the terminal's paste functionality, e.g. middle click) from another window that isn't vim. Most of the time, when I do this, I wanted to be in insert mode.

Obviously, this mistake can basically do anything that vim can do; most of the time there will be an early insert-mode character that will prevent most forms of document damage.

What's the best way to recover from this mistake?

  • In case of you didn't know about 'u' - undo.
    – ds6AUW
    Feb 5, 2015 at 8:51

1 Answer 1


Assuming that no :w or :write command was issued, all of the changes should still be in the buffer only, not written to disk.

An :earlier 30s command should restore your buffer to the state it was in 30 seconds ago.

Of course, if you want to discard all changes, there's always :quit!.

  • 1
    If :w did happen, will :earlier 30s still work?
    – durron597
    Feb 3, 2015 at 20:12
  • 1
    :earlier 30s restores the buffer to the state it was in 30 seconds ago. After reverting, you would then have to save it using :w. Feb 3, 2015 at 20:13

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