>> Well, could one not do something like the following?
>>
>>         :vnoremap <down> <down>o<down>o
>
> No, I did not mean "move the corners of the selection".
> I meants "move the contents".
> I meant "erase the contents at the old place and put the contents
> at the new place". Imagine moving text frames in the Word.
> This is what I mean. As if the selection are is a floating text frame.
> For example. Given the file:
>
> |--------------
> |abcdefghijk
> |123456789
>
> I select rectangle 2x2 "ab\n12" with Ctrl-V.
>
> I press Down and Right.
> The result shall be approximately like:
>
> |--------------
> |     defghijk
> | ab456789
>   12
>
> Depending on sophistication, and text under
> the moving rectangle can be either erase with blanks, or
> preserved. (more difficult). I'd make it an option.

I presume your example should be

 |--------------
 |  cdefghijk
 |ab3456789
 |12

with the "c\n3" and the "d" back over the "4" in there
which mysteriously vanished from your example.

The following suite of mappings seems to do what you
describe:

  :vnoremap <down> ygvr<space>gvoo<down>o<down>pgv
  :vnoremap <up> ygvr<space>gvoo<up>o<up>pgv
  :vnoremap <left> ygvr<space>gvoo<left>o<left>pgv
  :vnoremap <right> ygvr<space>gvoo<right>o<right>pgv

I'm not sure why they need the "oo" in them, but I may have
stumbled across a bug.  Without it, the 2nd and subsequent
uses mangle the selection when you move.  At least in the
<down> case...I just left it in there for the other 3 cases.

To reproduce it here, I simply

  :vnoremap <down> ygvr<space>gv<down>o<down>pgv

and then visual-block something and hit <down> twice.
Debugging showed that on the second attempt, the <down>
didn't move the selection properly.

I don't know so much about swapping bits around or
remembering what got overwritten for later replacement
rather than just erasing with spaces.  That, as you say,
would be considerably "more difficult".

-tim




Reply via email to