Re: Un-Vim like behaviour with cut-paste

Johan,

You are right. I'm afraid this is going to be the source of much bad publicity, but I implemented it like that because I didn't know how to paste over text *without* overwriting the register. I could emulate the other, vim-like, behavior by using different named registers.

I will fix it in the next release but, meanwhile, can anyone suggest how I could paste the contents of a register over some text *without* losing the contents of the register?

And I'm a bit surprised it's taken this long for someone to rightly complain

Re: Un-Vim like behaviour with cut-paste

I don't really understand the mapping, mainly, the last `P. I think there's an error.

My understanding:

<Esc> leaves visual mode, `. moves to the last edit point, `` moves back to where we started, gv goes back to visual mode, P pastes the last deleted text over the visual selection.

Why isn't this just the same as P?

In thinking of this and looking at my code, I'm thinking that the main confusion I have comes from two sources. One, when you type a reg modifier for paste in visual mode (say, "ap), what does the "a refer to? Where you paste from, or where you delete to? And second, when you paste in visual mode, the concept is a bit confusing, because it's an "exchange", right? There's no "correct" order between the paste-from and the yank-to, you need to have a third intermediate register?

I'll be happy for any help visualizing this behavior properly... my vim-fu is limited!

Re: Un-Vim like behaviour with cut-paste

Jon you're right, I left out one `

This is the mapping: vnoremap <C-x> <Esc> `.``gvP``P

<Esc> leaves visual mode, `. moves to the last edit point (call it point A), `` moves back to where we started, gv goes back to visual mode, P pastes the last deleted text over the visual selection. So far it's pretty much the same as P, except we have a mark for point A in place.

`` will now move back to where we last jumped from, that is, to point A from above. Lastly, P will now put the contents that were overwritten by the first P, which completes the swap.

This only works if putting in visual mode does an exchange, which is the difference between Vim and ViEmu in this regard.

The exchange behaviour is useful in a number of other ways too, so it would be great to get it implemented if it's not too hard.

If you're trying this out, there is one case where it won't work. If you try and swap a line for the next line, you'll delete the mark for point A and the command will fail. However, for that use case a plain ddp is of course easier.

* The register specifies where you paste from.* Regardless of which register you pasted from, the overwritten text is put into the default register, not into the specified register.* In Vim, an undo after a visual mode paste restores the text, but not the registers.

Re: Un-Vim like behaviour with cut-paste

Tomas, thanks for the very detailed description. I'm sure I'll be able to implement it fine with this. I have taken note of the request and I hope I can start working on it after ViEmu/2010 and Codekana/2010 are ready, together with the other core-vi request (:s//c, multiple key-chord mapping, etc...)