Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo a paste without undoing previous typing

Tags:

undo

vim

paste

In vim I frequently end up undoing more than I want to after a messed up paste from the system clipboard. Is there a better way?

To reproduce:

Open iTerm      # or terminal
vi              # open vim
i               # enter insert mode
type some stuff
Cmd-V           # paste the contents of the OS X clipboard

The paste is a mess because I haven't :set paste. So

Esc # enter command mode
u   # undo

but that undoes my typing as well as my paste.

Is there a different undo I can use? Apart from remembering to :set paste before pasting is there a better way to do this in general?

like image 661
Thomas David Baker Avatar asked Dec 17 '25 20:12

Thomas David Baker


1 Answers

This is not the answer you're looking for, but you really should stop using vim as a non-modal editor. If you want to paste then return to normal mode and use vim's paste commands. Assuming that you have a vim version with clipboard access this should do the trick "+p. You can also facilitate this by setting your unnamed register to be the + (or *) register, such that pasting from clipboard becomes a simple p.

The following question has a great answer that includes all this information How to make vim paste from (and copy to) system's clipboard?.

like image 150
Vitor Avatar answered Dec 20 '25 13:12

Vitor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!