1

Re: Un-Vim like behaviour with cut-paste

Hi there,

Just noticed some behaviour with ViEmu which is not quite like Vim. For example:

      1. Given the text "ALPHA, BETA", enter visual mode, highlight "BETA" and hit 'd' to delete.
      2. Enter visual mode, highlight "ALPHA" and hit 'p' to paste (Should replace "ALPHA" with "BETA", and put "ALPHA" in the yank buffer).
      3. Move cursor somewhere and 'p' for paste - should paste "ALPHA", but instead pastes "BETA".

Normally this behaviour is used for swapping bits of text around.

Regards,

Johan.

EDIT: This happens with "Default yank/paste to/from Windows clipboard" on or off.

Last edited by jventer (2006-05-07 22:55:54)

2

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 smile

3

Re: Un-Vim like behaviour with cut-paste

I stumbled across this the other day when I was trying to swap lines and words. Apart from being generally useful to easily overwrite stuff, its implementation allows some really cool stuff:

Delete some text somewhere.
Select some new text that you want to swap with in any visual mode.
vnoremap <C-X> <Esc>`.``gvP`P

In gvim, this swaps the selected text for the most recently deleted text, which is _very_ handy.

Any chance of implementing this?

4

Re: Un-Vim like behaviour with cut-paste

Tomas,

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!

Best regards,

  -- Jon

5

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.

Now, for your questions of visual mode put (or exchange, as might be a better name) implementation:

* 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.

6

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...)

7

Re: Un-Vim like behaviour with cut-paste

Any news on this ?
I quite like how I can paste on a visual block without changing the default register.. but I'd rather lose that if it's to get better Vim compatibility.