pvk7 / vim

Automatically exported from code.google.com/p/vim
0 stars 0 forks source link

Insert in Visual mode gives wrong result #193

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Inserting in Visual mode (see :help v_I) gives incorrect results.

What steps will reproduce the problem?

1. Create a 1-line ~/.vimrc containing:

inoremap <bs>  <c-g>u<bs>

2. Create a sample 3-line file containing:

#include "foo.h"
#include "bar.h"
#include "foobar.h"

3. Run the following command:
$ vim --noplugin test.c \
    -c 'call feedkeys("ff\<C-V>jjIxxxx\<BS>\<BS>yy/\<Esc>")'

What is the expected output? What do you see instead?

Observe that the Vim buffer contains:

#include "xxxxyy/foo.h"
#include "bar.yy/foo.h"
#include "foobyy/foo.ar.h"

This looks quite messed up. I would expect instead to obtain this:

#include "xxyy/foo.h"
#include "xxyy/bar.h"
#include "xxyy/foobar.h"

It looks like a bug to me or am I missing something?

The bug is triggered by the mapping in the ~/.vimrc.
If I comment out the mapping in the ~/.vimrc, then
I obtain the above expected result.

What version of the product are you using? On what operating system?

Vim-7.4.155 (huge) on Linux x86_64 (xubuntu-13.10).

Original issue reported on code.google.com by dominiqu...@gmail.com on 15 Jan 2014 at 12:47

GoogleCodeExporter commented 9 years ago
I noticed that bug does not happen with Vim-7.4, but it happens with the
latest Vim-7.4.155. So it's a recent regression.

Doing a bisection to find the change that introduces the bug...

Vim-7.4     -> OK
Vim-7.4.050 -> OK
Vim-7.4.075 -> OK
Vim-7.4.081 -> OK
Vim-7.4.084 -> OK
Vim-7.4.085 -> BUG
Vim-7.4.087 -> BUG
Vim-7.4.100 -> BUG
Vim-7.4.155 -> BUG

So the it's patch 7.4.085 that introduced the bug, which
looks plausible as it modifies insert in visual mode
according its description:

changeset:   5471:70c3289803b3
tag:         v7-4-085
user:        Bram Moolenaar <bram@vim.org>
date:        Mon Nov 11 01:29:22 2013 +0100
files:       src/ops.c src/testdir/test39.in src/testdir/test39.ok src/version.c
description:
updated for version 7.4.085
Problem:    When inserting text in Visual block mode and moving the cursor the
            wrong text gets repeated in other lines.
Solution:   Use the '[ mark to find the start of the actually inserted text.
            (Christian Brabandt)

Original comment by dominiqu...@gmail.com on 15 Jan 2014 at 1:11

GoogleCodeExporter commented 9 years ago
This is to be expected, since <C-g>u set's the '[ mark and that confuses Vim. I 
don't see a way how to fix this currently, besides setting another global 
variable, that tracks where inserting text really started.

Original comment by chrisbr...@googlemail.com on 15 Jan 2014 at 6:57

GoogleCodeExporter commented 9 years ago
Christian wrote:

> This is to be expected, since <C-g>u set's the '[ mark and
> that confuses Vim. I don't see a way how to fix this currently,
> besides setting another global variable, that tracks where
> inserting text really started.

I would not call it "expected" from the user point of view, especially
since it's a regression and since the outcome looks random to me.
Instead of getting...

#include "xxyy/foobar.h"

...for the 3rd line after typing the command, I get...

#include "foobyy/foo.ar.h""

I cannot think that it makes sense.

It caused me some real confusion when editing some files at work, until
I found what caused the bug. Bug will probably affect more users.

What you mean by "expected" here is that you
understand why the bug happens as a developer. 

Cheers
Dominique

Original comment by dominiqu...@gmail.com on 16 Jan 2014 at 12:48

GoogleCodeExporter commented 9 years ago
The patch posted by Christian Brabandt in vim-dev (on Jan 16, 2014) fixes the 
bug.

However, Christian's patch contains a small mistake: variable 
update_Insstart_orig is defined in between #ifdef FEAT_INS_EXPAND, yet it is 
used outside #ifdef FEAT_INS_EXPAND. So it fails to compile with vim tiny 
(configure --with-features=tiny):

edit.c:346:5: error: use of undeclared identifier 'update_Insstart_orig'
    update_Insstart_orig = TRUE;
    ^
edit.c:639:6: error: use of undeclared identifier 'update_Insstart_orig'
        if (update_Insstart_orig)
            ^

Attached patch is a minor correction of Christian's patch so that
it builds successfully with vim tiny.

Original comment by dominiqu...@gmail.com on 15 Feb 2014 at 10:14

Attachments:

GoogleCodeExporter commented 9 years ago
fixed by 7.4.186

Original comment by chrisbr...@googlemail.com on 2 Oct 2014 at 8:11