[patch] Visual-block-change and cursor-keys

46 views
Skip to first unread message

Christian Brabandt

unread,
Sep 28, 2013, 9:10:58 AM9/28/13
to vim...@vim.org
Bram,
when using Visual-block insert or append, you can't use the cursor keys
to move the cursor to a different location. This will confuse vim.

e.g. consider this block

aaaaaaa
bbbbbbb
ccccccc

Put the Cursor on the first a, and press
l<C-V>jjlllI<Right><Right><Space><Space>

The result will look like this:

aaa aaaa
baabbbbbb
caacccccc

While the result should look like this

aaa aaaa
bbb bbbb
ccc cccc

Attached patch fixes it. It is a little bit fragile, because it depends
on the '[ mark being set correctly, but it seems to work pretty well. If
some plugin messes with this mark in Visual-block mode, it will probably
not be worse then the current situation, so this should be ok.

BTW: I tried to make a new test case for this, but failed, because you
can't use <C-O> in Visual-block Insert/Append mode (this should probably
also be fixed sometimes, this is pretty obvious, since the op_change()
function doesn't care about the return value of the edit() function) and
using the raw terminal keys e.g. <ESC>OC for right are taken literally.

Disclaimer, this problem has first been mentioned at stackoverflow:
http://stackoverflow.com/questions/19030928


regards,
Christian
--
block_change.diff

Bram Moolenaar

unread,
Sep 28, 2013, 4:24:32 PM9/28/13
to Christian Brabandt, vim...@vim.org

Christian Brabandt wrote:

> Bram,
> when using Visual-block insert or append, you can't use the cursor keys
> to move the cursor to a different location. This will confuse vim.
>
> e.g. consider this block
>
> aaaaaaa
> bbbbbbb
> ccccccc
>
> Put the Cursor on the first a, and press
> l<C-V>jjlllI<Right><Right><Space><Space>
>
> The result will look like this:
>
> aaa aaaa
> baabbbbbb
> caacccccc
>
> While the result should look like this
>
> aaa aaaa
> bbb bbbb
> ccc cccc

I suppose so. Or repeating the insert should be omitted.

> Attached patch fixes it. It is a little bit fragile, because it depends
> on the '[ mark being set correctly, but it seems to work pretty well. If
> some plugin messes with this mark in Visual-block mode, it will probably
> not be worse then the current situation, so this should be ok.
>
> BTW: I tried to make a new test case for this, but failed, because you
> can't use <C-O> in Visual-block Insert/Append mode (this should probably
> also be fixed sometimes, this is pretty obvious, since the op_change()
> function doesn't care about the return value of the edit() function) and
> using the raw terminal keys e.g. <ESC>OC for right are taken literally.

Can't you just use the example you gave above? No CTRL-O there.


--
Eight Megabytes And Continually Swapping.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian Brabandt

unread,
Sep 29, 2013, 8:16:19 AM9/29/13
to vim...@vim.org
On Sa, 28 Sep 2013, Bram Moolenaar wrote:

> Can't you just use the example you gave above? No CTRL-O there.

Here is an updated patch, including a test. Using :exe one can use the
cursor keys just like normal, while if you use Cursor Right literally in
the test file, this will look like ^[OC, which will then be interpreted
like <esc>, "O" and finally "C" when running the test.

regards,
Christian
--
Fast jede Frau w�re gern treu. Schwierig ist es blo�, den Mann zu
finden, dem man treu sein kann.
-- Marlene Dietrich
block_insert.diff

Bram Moolenaar

unread,
Sep 29, 2013, 11:38:01 AM9/29/13
to Christian Brabandt, vim...@vim.org

Christian Brabandt wrote:

> On Sa, 28 Sep 2013, Bram Moolenaar wrote:
>
> > Can't you just use the example you gave above? No CTRL-O there.
>
> Here is an updated patch, including a test. Using :exe one can use the
> cursor keys just like normal, while if you use Cursor Right literally in
> the test file, this will look like ^[OC, which will then be interpreted
> like <esc>, "O" and finally "C" when running the test.

I'm glad you found a solution. Thanks!


--
ARTHUR: Who are you?
TALL KNIGHT: We are the Knights Who Say "Ni"!
BEDEVERE: No! Not the Knights Who Say "Ni"!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Reply all
Reply to author
Forward
0 new messages