JMK
JMK

Reputation: 28080

How do I cancel a paste operation in Vim?

I had rather a lot of text on my clipboard whenever I accidentally right clicked inside Putty (with Vim open), and Vim has initiated a paste operation which has been going for around ten minutes now.

I don't want to lose my unsaved work, is there a way to instruct Vim to stop pasting text?

Upvotes: 17

Views: 8246

Answers (3)

Austin Zimmerman
Austin Zimmerman

Reputation: 41

I know this is really old but the top answer is not right and I was clearly having a similar issue to OP. (accidentally pasted like a million lines of json into vim)

Keep in mind this may not allow you to save your work (but you can probably salvage something from the .swp file)

All you need to do is open a new terminal window and enter pkill vim into the command line.

Upvotes: 4

Gilles Quénot
Gilles Quénot

Reputation: 185831

Depending os your configuration, there's chances that you have a swap file (backup) in .nameOfTheOpenedFile.swp (substitute nameOfTheOpenedFile with the name for your file).

To recover the file :

vim -r .nameOfTheOpenedFile.swp

Upvotes: 0

Michael Kristofik
Michael Kristofik

Reputation: 35218

If you're in normal mode, Ctrl-C aborts the current command in progress. Then press u to undo anything that changed before you stopped it.

Upvotes: 9

Related Questions