Hi xaizek, ChrisB and Bram,

2016-7-16(Sat) 2:08:47 UTC+9 vim-dev ML:
> On Fr, 15 Jul 2016, h_east wrote:
> 
> 
> 
> > Hi xaizek and list,
> 
> > 
> 
> > 2016-7-15(Fri) 2:30:56 UTC+9 xaizek:
> 
> > > Run Vim like this:
> 
> > > 
> 
> > > vim -N -u NONE -c 'set virtualedit=all'
> 
> > > 
> 
> > > 
> 
> > > 
> 
> > > Enter the following text:
> 
> > > 
> 
> > > <tabulation>1
> 
> > > 
> 
> > > 
> 
> > > 
> 
> > > See how cursor position relative to tabulation affects placement of 
> > > incremented/decremented number:
> 
> > > 
> 
> > > " "|" designates cursor position
> 
> > > |       1
> 
> > > " <ctrl-x> gives this (OK)
> 
> > > |       0
> 
> > > " moving cursor to the right before pressing <ctrl-x> moves number (not 
> > > OK)
> 
> > >  |       -1
> 
> > >   |       -2
> 
> > >    |       -3
> 
> > > " etc.
> 
> > > 
> 
> > > 
> 
> > > 
> 
> > > Virtual space seems to be counted as if it was a real character.
> 
> > > 
> 
> > > 
> 
> > > —
> 
> > > You are receiving this because you are subscribed to this thread.
> 
> > > Reply to this email directly, view it on GitHub, .
> 
> > 
> 
> > I can reproduce your reported issue.
> 
> 
> 
> Yeah, the problem is, that ins_str() changes the buffer and actually
> 
> inserts blanks, if the cursor is beyond the line end.
> 
> 
> 
> I tried this patch:
> 
> ```diff
> 
> --- a/src/ops.c
> 
> +++ b/src/ops.c
> 
> @@ -5835,7 +5835,18 @@ do_addsub(
> 
>                 *ptr++ = '0';
> 
>         *ptr = NUL;
> 
>         STRCAT(buf1, buf2);
> 
> +#ifdef FEAT_VIRTUALEDIT
> 
> +       if (virtual_active())
> 
> +       {
> 
> +           save_cursor = curwin->w_cursor;
> 
> +           curwin->w_cursor.coladd = 0;
> 
> +       }
> 
> +#endif
> 
>         ins_str(buf1);          /* insert the new number */
> 
> +#ifdef FEAT_VIRTUALEDIT
> 
> +       if (virtual_active())
> 
> +           curwin->w_cursor.coladd = save_cursor.coladd;
> 
> +#endif
> 
>         vim_free(buf1);
> 
>         endpos = curwin->w_cursor;
> 
>         if (did_change && curwin->w_cursor.col)
> 
> ```
> 
> this almost works, except that after incrementing/decrementing ml_get()
> 
> still returns the wrong line. I don't know why yet.
> 
> 
> 
> On the other hand, one could argue, that the number shouldn't be 
> 
> incremented/decremented at all if the cursor is actually not on a 
> 
> number, so you could even consider the successful increment to be a bug.

ChrisB>
Your patch is a good hint for me. Thanks!

I wrote a patch with a test.
Please check and include this.

--
Best regards,
Hirohito Higashi (a.k.a. h_east)

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/ops.c b/src/ops.c
index 1767eb5..0011912 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -5468,17 +5468,32 @@ do_addsub(
     int		maxlen = 0;
     pos_T	startpos;
     pos_T	endpos;
+#ifdef FEAT_VIRTUALEDIT
+    colnr_T	save_coladd = 0;
+#endif
 
     dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL);	/* "heX" */
     dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL);	/* "Octal" */
     dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL);	/* "Bin" */
     doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL);	/* "alPha" */
 
+#ifdef FEAT_VIRTUALEDIT
+    if (virtual_active())
+    {
+	save_coladd = pos->coladd;
+	pos->coladd = 0;
+    }
+#endif
+
     curwin->w_cursor = *pos;
     ptr = ml_get(pos->lnum);
     col = pos->col;
 
-    if (*ptr == NUL)
+    if (*ptr == NUL
+#ifdef FEAT_VIRTUALEDIT
+	    || col + !!save_coladd >= (int)STRLEN(ptr)
+#endif
+	    )
 	goto theend;
 
     /*
@@ -5854,8 +5869,15 @@ do_addsub(
 theend:
     if (visual)
 	curwin->w_cursor = save_cursor;
-    else if (did_change)
-	curwin->w_set_curswant = TRUE;
+    else
+    {
+	if (did_change)
+	    curwin->w_set_curswant = TRUE;
+#ifdef FEAT_VIRTUALEDIT
+	else if (virtual_active())
+	    curwin->w_cursor.coladd = save_coladd;
+#endif
+    }
 
     return did_change;
 }
diff --git a/src/testdir/test_increment.vim b/src/testdir/test_increment.vim
index e53b569..2f92141 100644
--- a/src/testdir/test_increment.vim
+++ b/src/testdir/test_increment.vim
@@ -1,4 +1,4 @@
-" Tests for using Ctrl-A/Ctrl-X on visual selections
+" Tests for using Ctrl-A/Ctrl-X
 
 func SetUp()
   new dummy
@@ -756,5 +756,40 @@ func Test_normal_increment_03()
   call assert_equal([0, 3, 25, 0], getpos('.'))
 endfunc
 
+func Test_normal_increment_with_virtualedit()
+  set virtualedit=all
+
+  call setline(1, ["\<TAB>1"])
+  exec "norm! 0\<C-A>"
+  call assert_equal("\<TAB>2", getline(1))
+  call assert_equal([0, 1, 2, 0], getpos('.'))
+
+  call setline(1, ["\<TAB>1"])
+  exec "norm! 0l\<C-A>"
+  call assert_equal("\<TAB>2", getline(1))
+  call assert_equal([0, 1, 2, 0], getpos('.'))
+
+  call setline(1, ["\<TAB>1"])
+  exec "norm! 07l\<C-A>"
+  call assert_equal("\<TAB>2", getline(1))
+  call assert_equal([0, 1, 2, 0], getpos('.'))
+
+  call setline(1, ["\<TAB>1"])
+  exec "norm! 0w\<C-A>"
+  call assert_equal("\<TAB>2", getline(1))
+  call assert_equal([0, 1, 2, 0], getpos('.'))
+
+  call setline(1, ["\<TAB>1"])
+  exec "norm! 0wl\<C-A>"
+  call assert_equal("\<TAB>1", getline(1))
+  call assert_equal([0, 1, 3, 0], getpos('.'))
+
+  call setline(1, ["\<TAB>1"])
+  exec "norm! 0w30l\<C-A>"
+  call assert_equal("\<TAB>1", getline(1))
+  call assert_equal([0, 1, 3, 29], getpos('.'))
+
+  set virtualedit&
+endfunc
 
 " vim: tabstop=2 shiftwidth=2 expandtab

Raspunde prin e-mail lui