Skip to content

Instantly share code, notes, and snippets.

@h-east
Last active December 28, 2015 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-east/ad3d22c13188de1466d3 to your computer and use it in GitHub Desktop.
Save h-east/ad3d22c13188de1466d3 to your computer and use it in GitHub Desktop.
diff --git a/src/Makefile b/src/Makefile
index 3f29d46..4b8e2fb 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1914,7 +1914,6 @@ test1 \
test_erasebackword \
test_eval \
test_fixeol \
- test_increment \
test_insertcount \
test_listchars \
test_listlbr \
diff --git a/src/normal.c b/src/normal.c
index 89c67d9..5cbf7cc 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -3629,11 +3629,51 @@ prep_redo_visual(cap)
}
if (curbuf->b_visual.vi_curswant == MAXCOL)
AppendCharToRedobuff('$');
- else if (curbuf->b_visual.vi_end.col > curbuf->b_visual.vi_start.col)
+ else
{
- AppendNumberToRedobuff(curbuf->b_visual.vi_end.col
- - curbuf->b_visual.vi_start.col - 1);
- AppendCharToRedobuff(' ');
+ if (VIsual_mode == 'v')
+ {
+ AppendNumberToRedobuff(0);
+ if (curbuf->b_visual.vi_end.col > 0)
+ {
+ AppendNumberToRedobuff(curbuf->b_visual.vi_end.col);
+ AppendCharToRedobuff(' ');
+ }
+ }
+ else if (VIsual_mode == Ctrl_V)
+ {
+ colnr_T vcol, start_vcol, end_vcol;
+ colnr_T col, start_col, end_col;
+ char_u *line, *ptr;
+ int ptr_len;
+
+ getvcol(curwin, &curbuf->b_visual.vi_start, NULL, &start_vcol, NULL);
+ getvcol(curwin, &curbuf->b_visual.vi_end, NULL, &end_vcol, NULL);
+
+ line = ptr = ml_get(curbuf->b_visual.vi_end.lnum);
+ ptr_len = (int)STRLEN(ptr);
+ vcol = col = 0;
+ while (vcol < start_vcol && col < ptr_len)
+ {
+ vcol += lbr_chartabsize(line, ptr, vcol);
+ col += MB_PTR2LEN(ptr);
+ mb_ptr_adv(ptr);
+ }
+ start_col = col;
+
+ while (vcol < end_vcol && col < ptr_len)
+ {
+ vcol += lbr_chartabsize(line, ptr, vcol);
+ col += MB_PTR2LEN(ptr);
+ mb_ptr_adv(ptr);
+ }
+ end_col = col;
+ if (end_col - start_col > 0)
+ {
+ AppendNumberToRedobuff(end_col - start_col);
+ AppendCharToRedobuff(' ');
+ }
+ }
}
}
AppendNumberToRedobuff(cap->count1);
diff --git a/src/ops.c b/src/ops.c
index c86d8de..7c1cf66 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -5339,31 +5339,6 @@ block_prep(oap, bdp, lnum, is_del)
bdp->textstart = pstart;
}
-#ifdef FEAT_RIGHTLEFT
-static void reverse_line __ARGS((char_u *s));
-
- static void
-reverse_line(s)
- char_u *s;
-{
- int i, j;
- char_u c;
-
- if ((i = (int)STRLEN(s) - 1) <= 0)
- return;
-
- curwin->w_cursor.col = i - curwin->w_cursor.col;
- for (j = 0; j < i; j++, i--)
- {
- c = s[i]; s[i] = s[j]; s[j] = c;
- }
-}
-
-# define RLADDSUBFIX(ptr) if (curwin->w_p_rl) reverse_line(ptr);
-#else
-# define RLADDSUBFIX(ptr)
-#endif
-
/*
* add or subtract 'Prenum1' from a number in a line
* 'command' is CTRL-A for add, CTRL-X for subtract
@@ -5397,12 +5372,18 @@ do_addsub(command, Prenum1, g_cmd)
int was_positive = TRUE;
int visual = VIsual_active;
int i;
- int lnum = curwin->w_cursor.lnum;
- int lnume = curwin->w_cursor.lnum;
+ int lnum;
+ int lnume;
int startcol = 0;
int did_change = FALSE;
pos_T t = curwin->w_cursor;
int maxlen = 0;
+ int vcol;
+ colnr_T start_vcol = 0;
+ colnr_T end_vcol = 0;
+ colnr_T stop;
+ int ptr_len;
+ char_u *line;
dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */
dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); /* "Octal" */
@@ -5411,7 +5392,6 @@ do_addsub(command, Prenum1, g_cmd)
/*
* First check if we are on a hexadecimal number, after the "0x".
*/
- col = curwin->w_cursor.col;
if (VIsual_active)
{
if (lt(curwin->w_cursor, VIsual))
@@ -5420,39 +5400,61 @@ do_addsub(command, Prenum1, g_cmd)
VIsual = t;
}
+ /* store visual area for 'gv' */
+ curbuf->b_visual.vi_start = VIsual;
+ curbuf->b_visual.vi_end = curwin->w_cursor;
+ curbuf->b_visual.vi_mode = VIsual_mode;
+ curbuf->b_visual.vi_curswant = curwin->w_curswant;
+
+ if (VIsual_mode != 'V')
+ {
+ getvcol(curwin, &VIsual, NULL, &start_vcol, NULL);
+ getvcol(curwin, &curwin->w_cursor, NULL, &end_vcol, NULL);
+ }
+
ptr = ml_get(VIsual.lnum);
- RLADDSUBFIX(ptr);
if (VIsual_mode == 'V')
{
VIsual.col = 0;
curwin->w_cursor.col = (colnr_T)STRLEN(ptr);
}
- else if (VIsual_mode == Ctrl_V && VIsual.col > curwin->w_cursor.col)
+ else if (VIsual_mode == Ctrl_V && start_vcol > end_vcol)
{
- t = VIsual;
- VIsual.col = curwin->w_cursor.col;
- curwin->w_cursor.col = t.col;
- }
+ t.col = start_vcol;
+ start_vcol = end_vcol;
+ end_vcol = t.col;
- /* store visual area for 'gv' */
- curbuf->b_visual.vi_start = VIsual;
- curbuf->b_visual.vi_end = curwin->w_cursor;
- curbuf->b_visual.vi_mode = VIsual_mode;
- curbuf->b_visual.vi_curswant = curwin->w_curswant;
+ line = ptr = ml_get(VIsual.lnum);
+ ptr_len = (int)STRLEN(ptr);
+ vcol = col = 0;
+ while (vcol < start_vcol && col < ptr_len)
+ {
+ vcol += lbr_chartabsize(line, ptr, vcol);
+ col += MB_PTR2LEN(ptr);
+ mb_ptr_adv(ptr);
+ }
+ VIsual.col = col;
- if (VIsual_mode != 'v')
- startcol = VIsual.col < curwin->w_cursor.col ? VIsual.col
- : curwin->w_cursor.col;
- else
- startcol = VIsual.col;
- col = startcol;
+ line = ptr = ml_get(curwin->w_cursor.lnum);
+ ptr_len = (int)STRLEN(ptr);
+ vcol = col = 0;
+ while (vcol < end_vcol && col < ptr_len)
+ {
+ vcol += lbr_chartabsize(line, ptr, vcol);
+ col += MB_PTR2LEN(ptr);
+ mb_ptr_adv(ptr);
+ }
+ curwin->w_cursor.col = col;
+ }
+
+ col = startcol = VIsual.col;
lnum = VIsual.lnum;
lnume = curwin->w_cursor.lnum;
}
else
{
+ col = curwin->w_cursor.col;
ptr = ml_get_curline();
- RLADDSUBFIX(ptr);
if (dohex)
while (col > 0 && vim_isxdigit(ptr[col]))
@@ -5484,37 +5486,89 @@ do_addsub(command, Prenum1, g_cmd)
&& !(doalp && ASCII_ISALPHA(ptr[col])))
--col;
}
+ lnum = lnume = curwin->w_cursor.lnum;
}
for (i = lnum; i <= lnume; i++)
{
- colnr_T stop = 0;
-
+ stop = 0;
t = curwin->w_cursor;
curwin->w_cursor.lnum = i;
- ptr = ml_get_curline();
- RLADDSUBFIX(ptr);
- if ((int)STRLEN(ptr) <= col)
+ line = ptr = ml_get_curline();
+ ptr_len = (int)STRLEN(ptr);
+ if (ptr_len <= col && !(visual && VIsual_mode == Ctrl_V))
/* try again on next line */
continue;
if (visual)
{
- if (VIsual_mode == 'v'
- && i == lnume)
- stop = curwin->w_cursor.col;
- else if (VIsual_mode == Ctrl_V
- && curbuf->b_visual.vi_curswant != MAXCOL)
- stop = curwin->w_cursor.col;
+ vcol = col = 0;
+ if (VIsual_mode == 'v' && i == lnum)
+ {
+ vcol = start_vcol;
+ col = VIsual.col;
+ }
+ else if (VIsual_mode == Ctrl_V)
+ {
+ while (vcol < start_vcol && col < ptr_len)
+ {
+ vcol += lbr_chartabsize(line, ptr, vcol);
+ col += MB_PTR2LEN(ptr);
+ mb_ptr_adv(ptr);
+ }
+ }
- while (ptr[col] != NUL
- && !vim_isdigit(ptr[col])
- && !(doalp && ASCII_ISALPHA(ptr[col])))
+ if ((VIsual_mode == 'v' && i == lnume) || VIsual_mode == Ctrl_V)
{
- if (col > 0 && col == stop)
- break;
- ++col;
+ startcol = stop = col;
+ while (vcol < end_vcol && stop < ptr_len)
+ {
+ vcol += lbr_chartabsize(line, ptr, vcol);
+ stop += MB_PTR2LEN(ptr);
+ mb_ptr_adv(ptr);
+ }
+ if (vcol > end_vcol && stop >= ptr_len)
+ /* try again on next line */
+ continue;
+ if (curbuf->b_visual.vi_curswant == MAXCOL)
+ stop = ptr_len - 1;
+
+ if ((VIsual_mode == 'v' && i == lnum) || VIsual_mode == Ctrl_V)
+ vcol = start_vcol;
+ else
+ vcol = 0;
+ col = startcol;
+ ptr = ml_get_curline() + startcol;
+
+ while ((curbuf->b_visual.vi_curswant == MAXCOL
+ || vcol < end_vcol) && col < ptr_len
+ && !vim_isdigit(*ptr)
+ && !(doalp && ASCII_ISALPHA(*ptr)))
+ {
+ if (col > 0 && col == stop)
+ break;
+ vcol += lbr_chartabsize(line, ptr, vcol);
+ col += MB_PTR2LEN(ptr);
+ mb_ptr_adv(ptr);
+ }
+
+ if (curbuf->b_visual.vi_curswant != MAXCOL && vcol > end_vcol)
+ continue;
+ ptr = ml_get_curline();
}
+ else
+ {
+ while (ptr[col] != NUL
+ && !vim_isdigit(ptr[col])
+ && !(doalp && ASCII_ISALPHA(ptr[col])))
+ {
+ if (col > 0 && col == stop)
+ break;
+ ++col;
+ }
+ }
+ curwin->w_cursor.col = col;
+ ptr = ml_get_curline();
if (col > startcol && ptr[col - 1] == '-')
{
negative = TRUE;
@@ -5592,22 +5646,9 @@ do_addsub(command, Prenum1, g_cmd)
}
/* get the number value (unsigned) */
if (visual && VIsual_mode != 'V')
- {
- if (VIsual_mode == 'v')
- {
- if (i == lnum)
- maxlen = (lnum == lnume
- ? curwin->w_cursor.col - col + 1
- : (int)STRLEN(ptr) - col);
- else
- maxlen = (i == lnume ? curwin->w_cursor.col - col + 1
- : (int)STRLEN(ptr) - col);
- }
- else if (VIsual_mode == Ctrl_V)
- maxlen = (curbuf->b_visual.vi_curswant == MAXCOL
- ? (int)STRLEN(ptr) - col
- : curwin->w_cursor.col - col + 1);
- }
+ maxlen = (curbuf->b_visual.vi_curswant == MAXCOL
+ ? (int)STRLEN(ptr) - col
+ : stop - col + 1);
vim_str2nr(ptr + col, &hex, &length, dooct, dohex, NULL, &n,
maxlen);
@@ -5764,10 +5805,6 @@ do_addsub(command, Prenum1, g_cmd)
col = 0;
Prenum1 += offset;
curwin->w_set_curswant = TRUE;
-#ifdef FEAT_RIGHTLEFT
- ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE);
- RLADDSUBFIX(ptr);
-#endif
}
if (visual)
/* cursor at the top of the selection */
diff --git a/src/testdir/Make_amiga.mak b/src/testdir/Make_amiga.mak
index d60f1a1..514e8d1 100644
--- a/src/testdir/Make_amiga.mak
+++ b/src/testdir/Make_amiga.mak
@@ -50,7 +50,6 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
test_erasebackword.out \
test_eval.out \
test_fixeol.out \
- test_increment.out \
test_insertcount.out \
test_listchars.out \
test_listlbr.out \
@@ -205,7 +204,6 @@ test_command_count.out: test_command_count.in
test_comparators.out: test_comparators.in
test_erasebackword.out: test_erasebackword.in
test_eval.out: test_eval.in
-test_increment.out: test_increment.in
test_fixeol.out: test_fixeol.in
test_insertcount.out: test_insertcount.in
test_listchars.out: test_listchars.in
diff --git a/src/testdir/Make_dos.mak b/src/testdir/Make_dos.mak
index 8dbe97e..583d81b 100644
--- a/src/testdir/Make_dos.mak
+++ b/src/testdir/Make_dos.mak
@@ -49,7 +49,6 @@ SCRIPTS = test3.out test4.out test5.out test6.out test7.out \
test_erasebackword.out \
test_eval.out \
test_fixeol.out \
- test_increment.out \
test_insertcount.out \
test_listchars.out \
test_listlbr.out \
diff --git a/src/testdir/Make_ming.mak b/src/testdir/Make_ming.mak
index a7c98ee..f96940b 100644
--- a/src/testdir/Make_ming.mak
+++ b/src/testdir/Make_ming.mak
@@ -71,7 +71,6 @@ SCRIPTS = test3.out test4.out test5.out test6.out test7.out \
test_erasebackword.out \
test_eval.out \
test_fixeol.out \
- test_increment.out \
test_insertcount.out \
test_listchars.out \
test_listlbr.out \
diff --git a/src/testdir/Make_os2.mak b/src/testdir/Make_os2.mak
index 926411b..08d08cf 100644
--- a/src/testdir/Make_os2.mak
+++ b/src/testdir/Make_os2.mak
@@ -51,7 +51,6 @@ SCRIPTS = test1.out test3.out test4.out test5.out test6.out \
test_erasebackword.out \
test_eval.out \
test_fixeol.out \
- test_increment.out \
test_insertcount.out \
test_listchars.out \
test_listlbr.out \
diff --git a/src/testdir/Make_vms.mms b/src/testdir/Make_vms.mms
index 990ae5f..22d2537 100644
--- a/src/testdir/Make_vms.mms
+++ b/src/testdir/Make_vms.mms
@@ -110,7 +110,6 @@ SCRIPT = test1.out test2.out test3.out test4.out test5.out \
test_erasebackword.out \
test_eval.out \
test_fixeol.out \
- test_increment.out \
test_insertcount.out \
test_listchars.out \
test_listlbr.out \
diff --git a/src/testdir/Makefile b/src/testdir/Makefile
index 83350aa..7cd7584 100644
--- a/src/testdir/Makefile
+++ b/src/testdir/Makefile
@@ -50,7 +50,6 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
test_erasebackword.out \
test_eval.out \
test_fixeol.out \
- test_increment.out \
test_insertcount.out \
test_listchars.out \
test_listlbr.out \
@@ -72,7 +71,7 @@ SCRIPTS = test1.out test2.out test3.out test4.out test5.out test6.out \
test_writefile.out
NEW_TESTS = test_assert.res \
- test_alot.res
+ test_alot.res
SCRIPTS_GUI = test16.out
diff --git a/src/testdir/runtest.vim b/src/testdir/runtest.vim
index 0dc142e..6f3580b 100644
--- a/src/testdir/runtest.vim
+++ b/src/testdir/runtest.vim
@@ -38,7 +38,15 @@ endif
" Source the test script. First grab the file name, in case the script
" navigates away.
let testname = expand('%')
-source %
+let done = 0
+let fail = 0
+let errors = []
+try
+ source %
+catch
+ let fail += 1
+ call add(errors, 'Caught exception: ' . v:exception . ' @ ' . v:throwpoint)
+endtry
" Locate Test_ functions and execute them.
redir @q
@@ -46,9 +54,6 @@ function /^Test_
redir END
let tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g'))
-let done = 0
-let fail = 0
-let errors = []
for test in tests
if exists("*SetUp")
call SetUp()
diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim
index 21a5241..eb4fee4 100644
--- a/src/testdir/test_alot.vim
+++ b/src/testdir/test_alot.vim
@@ -4,3 +4,4 @@
source test_lispwords.vim
source test_sort.vim
source test_undolevels.vim
+source test_increment.vim
diff --git a/src/testdir/test_increment.in b/src/testdir/test_increment.in
deleted file mode 100644
index 2ae6b8a..0000000
--- a/src/testdir/test_increment.in
+++ /dev/null
@@ -1,620 +0,0 @@
-Tests for using Ctrl-A/Ctrl-X on visual selections
-
-Test cases
-==========
-
-1) Ctrl-A on visually selected number
-Text:
-foobar-10
- Expected:
- 1) Ctrl-A on start of line:
- foobar-9
- 2) Ctrl-A on visually selected "-10":
- foobar-9
- 3) Ctrl-A on visually selected "10":
- foobar-11
- 4) Ctrl-X on visually selected "-10"
- foobar-11
- 5) Ctrl-X on visually selected "10"
- foobar-9
-
-2) Ctrl-A on visually selected lines
-Text:
-10
-20
-30
-40
-
- Expected:
- 1) Ctrl-A on visually selected lines:
-11
-21
-31
-41
-
- 2) Ctrl-X on visually selected lines:
-9
-19
-29
-39
-
-3) g Ctrl-A on visually selected lines, with non-numbers in between
-Text:
-10
-
-20
-
-30
-
-40
-
- Expected:
- 1) 2 g Ctrl-A on visually selected lines:
-12
-
-24
-
-36
-
-48
- 2) 2 g Ctrl-X on visually selected lines
-8
-
-16
-
-24
-
-32
-
-4) Ctrl-A on non-number
-Text:
-foobar-10
- Expected:
- 1) visually select foobar:
- foobar-10
-
-5) g<Ctrl-A> on letter
-Test:
-a
-a
-a
-a
- Expected:
- 1) g Ctrl-A on visually selected lines
- b
- c
- d
- e
-
-6) g<Ctrl-A> on letter
-Test:
-z
-z
-z
-z
- Expected:
- 1) g Ctrl-X on visually selected lines
- y
- x
- w
- v
-
-7) <Ctrl-A> on letter
-Test:
-2
-1
-0
--1
--2
-
- Expected:
- 1) Ctrl-A on visually selected lines
- 3
- 2
- 1
- 0
- -1
-
- 2) Ctrl-X on visually selected lines
- 1
- 0
- -1
- -2
- -3
-8) Block increment on 0x9
-Text:
-0x9
-0x9
- Expected:
- 1) Ctrl-A on visually block selected region (cursor at beginning):
- 0xa
- 0xa
- 2) Ctrl-A on visually block selected region (cursor at end)
- 0xa
- 0xa
-
-9) Increment and redo
-Text:
-2
-2
-
-3
-3
-
- Expected:
- 1) 2 Ctrl-A on first 2 visually selected lines
- 4
- 4
- 2) redo (.) on 3
- 5
- 5
-10) sequentially decrement 1
-Text:
-1
-1
-1
-1
- Expected:
- 1) g Ctrl-X on visually selected lines
- 0
- -1
- -2
- -3
-
-11) visually block selected indented lines
-Text:
- 1
-1
- 1
- 1
- Expexted:
- 1) g Ctrl-A on block selected indented lines
- 2
-1
- 3
- 4
-
-12) visually selected several columns
-Text:
-0 0
-0 0
-0 0
- Expected:
- 1) 'v' select last zero and first zeroes
- 0 1
- 1 0
- 1 0
-
-13) visually selected part of columns
-Text:
-max: 100px
-max: 200px
-max: 300px
-max: 400px
- Expected:
- 1) 'v' on first two numbers Ctrl-A
- max: 110px
- max: 220px
- max: 330px
- max: 400px
- 2) 'v' on first two numbers Ctrl-X
- max: 90px
- max: 190px
- max: 290px
- max: 400px
-
-14) redo in block mode
-Text:
-1 1
-1 1
- Expected:
- 1) Ctrl-a on first column, redo on second column
- 2 2
- 2 2
-
-15) block select single numbers
-Text:
-101
- Expected:
- 1) Ctrl-a on visually selected zero
- 111
-
-16) increment right aligned numbers
-Text:
- 1
- 19
- 119
- Expected:
- 1) Ctrl-a on line selected region
- 2
- 20
- 120
-
-17) block-wise increment and redo
-Text:
- 100
- 1
-
- 100
- 1
-
- Expected:
- 1) Ctrl-V j $ on first block, afterwards '.' on second
- 101
- 2
-
- 101
- 2
-
-18) repeat of g<Ctrl-a>
-Text:
- 0
- 0
- 0
- 0
-
- Expected:
- 1) V 4j g<ctrl-a>, repeat twice afterwards with .
- 3
- 6
- 9
- 12
-
-19) increment on number with nrformat including alpha
-Text:
- 1
- 1a
-
- Expected:
- 1) <Ctrl-V>j$ <ctrl-a>
- 2
- 2a
-
-20) increment a single letter
-Text:
- a
-
- Expected:
- 1) <Ctrl-a> and cursor is on a
- b
-
-21) block-wise increment on part of hexadecimal
-Text:
-0x123456
-
- Expected:
- 1) Ctrl-V f3 <ctrl-a>
-0x124456
-
-
-
-STARTTEST
-:so small.vim
-:"
-:" Avoid CTRL-X being mapped in Visual mode for MS-Windows
-:vmapclear
-:"
-:" Test 1
-:/^S1=/+,/^E1=/-y a
-:/^E1=/+put a
-:/^E1=/+2put a
-f-v$:/^E1=/+3put a
-f1v$:/^E1=/+4put a
-f-v$:/^E1=/+5put a
-f1v$
-
-:" Test 2
-:/^S2=/+,/^E2=/-y a
-:/^E2=/+put a
-V3k$3j:.+put a
-V3k$
-
-:" Test 3
-:/^S3=/+,/^E3=/-y a
-:/^E3=/+put a
-V6k2g6j:.+put a
-V6k2g
-
-:" Test 4
-:/^S4=/+,/^E4=/-y a
-:/^E4=/+put a
-vf-
-
-:" Test 5
-:set nrformats+=alpha
-:/^S5=/+,/^E5=/-y a
-:/^E5=/+put a
-v3kg
-
-:" Test 6
-:/^S6=/+,/^E6=/-y a
-:/^E6=/+put a
-v3kg
-
-:" Test 7
-:set nrformats&vim
-:/^S7=/+,/^E7=/-y a
-:/^E7=/+put a
-V4k4j:.+put a
-V4k
-
-:" Test 8
-:/^S8=/+,/^E8=/-y a
-:/^E8=/+put a
-kj$j:.+put a
-k$+
-
-:" Test 9
-:/^S9=/+,/^E9=/-y a
-:/^E9=/+put a
-5kVj23j.
-
-:" Test 10
-:/^S10=/+,/^E10=/-y a
-:/^E10=/+put a
-V3kg
-
-: Test 11
-:/^S11=/+,/^E11=/-y a
-:/^E11=/+put a
-3kf13jg
-
-:" Test 12
-:/^S12=/+,/^E12=/-y a
-:/^E12=/+put a
-2k$v++
-
-:" Test 13
-:/^S13=/+,/^E13=/-y a
-:/^E13=/+put a
-3kf1l2j3j:.+put a
-3kf1l2j
-
-:" Test 14
-:/^S14=/+,/^E14=/-y a
-:/^E14=/+put a
-kw.
-
-:" Test 15
-:/^S15=/+,/^E15=/-y a
-:/^E15=/+put a
-lv
-
-:" Test 16
-:/^S16=/+,/^E16=/-y a
-:/^E16=/+put a
-V3k
-
-:" Test 17
-:/^S17=/+,/^E17=/-y a
-:/^E17=/+put a
-4kj$2j.
-
-:" Test 18
-:/^S18=/+,/^E18=/-y a
-:/^E18=/+put a
-V3kg..
-
-:" Test 19
-:set nrformats+=alpha
-:/^S19=/+,/^E19=/-y a
-:/^E19=/+put a
-k$
-:set nrformats&vim
-
-:" Test 20
-:set nrformats+=alpha
-:/^S20=/+,/^E20=/-y a
-:/^E20=/+put a
-:.put =col('.')
-:set nrformats&vim
-
-:" Test 21
-:/^S21=/+,/^E21=/-y a
-:/^E21=/+put a
-:set nrformats&vim
-f3
-
-:" Save the report
-:/^# Test 1/,$w! test.out
-:qa!
-
-
-# Test 1
-S1======
-foobar-10
-E1======
-
-
-
-# Test 2
-S2=====
-10
-20
-30
-40
-E2=====
-
-
-
-# Test 3
-S3=====
-10
-
-20
-
-30
-
-40
-E3=====
-
-
-
-# Test 4
-S4=====
-foobar-10
-E4=====
-
-
-
-# Test 5
-S5====
-a
-a
-a
-a
-E5====
-
-
-# Test 6
-S6====
-z
-z
-z
-z
-E6====
-
-
-
-# Test 7
-S7====
-2
-1
-0
--1
--2
-E7====
-
-
-
-# Test 8
-S8====
-0x9
-0x9
-E8====
-
-
-
-
-# Test 9
-S9====
-2
-2
-
-3
-3
-
-E9====
-
-
-
-
-# Test 10
-S10====
-1
-1
-1
-1
-E10====
-
-
-
-
-# Test 11
-S11====
- 1
-1
- 1
- 1
-E11====
-
-
-
-# Test 12
-S12====
-0 0
-0 0
-0 0
-E12====
-
-
-
-# Test 13
-S13====
-max: 100px
-max: 200px
-max: 300px
-max: 400px
-E13====
-
-
-
-# Test 14
-S14====
-1 1
-1 1
-E14====
-
-
-
-# Test 15
-S15====
-101
-E15====
-
-
-
-# Test 16
-S16====
- 1
- 19
- 119
-E16====
-
-
-
-# Test 17
-S17====
- 100
- 1
-
- 100
- 1
-E17====
-
-
-# Test 18
-S18====
-0
-0
-0
-0
-E18====
-
-
-
-# Test 19
-S19====
-1
-1a
-E19====
-
-
-
-# Test 20
-S20====
-a
-E20====
-
-
-
-# Test 21
-S21====
-0x123456
-E21====
-
-
-
-
-ENDTEST
-
diff --git a/src/testdir/test_increment.ok b/src/testdir/test_increment.ok
deleted file mode 100644
index 15d0e9b..0000000
--- a/src/testdir/test_increment.ok
+++ /dev/null
@@ -1,293 +0,0 @@
-# Test 1
-S1======
-foobar-10
-E1======
-
-foobar-9
-foobar-9
-foobar-11
-foobar-11
-foobar-9
-
-
-# Test 2
-S2=====
-10
-20
-30
-40
-E2=====
-
-11
-21
-31
-41
-
-9
-19
-29
-39
-
-# Test 3
-S3=====
-10
-
-20
-
-30
-
-40
-E3=====
-
-12
-
-24
-
-36
-
-48
-
-8
-
-16
-
-24
-
-32
-
-# Test 4
-S4=====
-foobar-10
-E4=====
-
-foobar-10
-
-
-# Test 5
-S5====
-a
-a
-a
-a
-E5====
-
-b
-c
-d
-e
-
-# Test 6
-S6====
-z
-z
-z
-z
-E6====
-
-y
-x
-w
-v
-
-
-# Test 7
-S7====
-2
-1
-0
--1
--2
-E7====
-
-3
-2
-1
-0
--1
-
-1
-0
--1
--2
--3
-
-# Test 8
-S8====
-0x9
-0x9
-E8====
-
-0xa
-0xa
-
-0xa
-0xa
-
-
-# Test 9
-S9====
-2
-2
-
-3
-3
-
-E9====
-
-4
-4
-
-5
-5
-
-
-
-
-# Test 10
-S10====
-1
-1
-1
-1
-E10====
-
-0
--1
--2
--3
-
-
-
-# Test 11
-S11====
- 1
-1
- 1
- 1
-E11====
-
- 2
-1
- 3
- 4
-
-
-# Test 12
-S12====
-0 0
-0 0
-0 0
-E12====
-
-0 1
-1 0
-1 0
-
-
-# Test 13
-S13====
-max: 100px
-max: 200px
-max: 300px
-max: 400px
-E13====
-
-max: 110px
-max: 210px
-max: 310px
-max: 400px
-
-max: 90px
-max: 190px
-max: 290px
-max: 400px
-
-# Test 14
-S14====
-1 1
-1 1
-E14====
-
-2 2
-2 2
-
-
-# Test 15
-S15====
-101
-E15====
-
-111
-
-
-# Test 16
-S16====
- 1
- 19
- 119
-E16====
-
- 2
- 20
- 120
-
-
-# Test 17
-S17====
- 100
- 1
-
- 100
- 1
-E17====
-
- 101
- 2
-
- 101
- 1
-
-# Test 18
-S18====
-0
-0
-0
-0
-E18====
-
-3
-6
-9
-12
-
-
-# Test 19
-S19====
-1
-1a
-E19====
-
-2
-2a
-
-
-# Test 20
-S20====
-a
-E20====
-
-b
-1
-
-
-# Test 21
-S21====
-0x123456
-E21====
-
-0x124456
-
-
-
-ENDTEST
-
diff --git a/src/testdir/test_increment.vim b/src/testdir/test_increment.vim
new file mode 100644
index 0000000..3ce679e
--- /dev/null
+++ b/src/testdir/test_increment.vim
@@ -0,0 +1,315 @@
+" Tests for using Ctrl-A/Ctrl-X on visual selections
+
+func SetUp()
+ new
+ set nrformats&vim
+endfunc
+
+func TearDown()
+ bwipe!
+endfunc
+
+" Ctrl-A on visually selected number
+func Test_visual_increment_01()
+ call setline(1, repeat(["foobaar-10"], 5))
+
+ call cursor(1, 1)
+ exec "norm! \<C-A>"
+ call assert_equal("foobaar-9", getline('.'))
+ call assert_equal([0, 1, 9, 0], getpos('.'))
+
+ call cursor(2, 1)
+ exec "norm! f-v$\<C-A>"
+ call assert_equal("foobaar-9", getline('.'))
+ call assert_equal([0, 2, 8, 0], getpos('.'))
+
+ call cursor(3, 1)
+ exec "norm! f1v$\<C-A>"
+ call assert_equal("foobaar-11", getline('.'))
+ call assert_equal([0, 3, 9, 0], getpos('.'))
+
+ call cursor(4, 1)
+ exec "norm! f-v$\<C-X>"
+ call assert_equal("foobaar-11", getline('.'))
+ call assert_equal([0, 4, 8, 0], getpos('.'))
+
+ call cursor(5, 1)
+ exec "norm! f1v$\<C-X>"
+ call assert_equal("foobaar-9", getline('.'))
+ call assert_equal([0, 5, 9, 0], getpos('.'))
+endfunc
+
+" Ctrl-A on visually selected lines
+func Test_visual_increment_02()
+ call setline(1, ["10", "20", "30", "40"])
+ exec "norm! GV3k$\<C-A>"
+ call assert_equal(["11", "21", "31", "41"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+
+ call setline(1, ["10", "20", "30", "40"])
+ exec "norm! GV3k$\<C-X>"
+ call assert_equal(["9", "19", "29", "39"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" g Ctrl-A on visually selected lines, with non-numbers in between
+func Test_visual_increment_03()
+ call setline(1, ["10", "", "20", "", "30", "", "40"])
+ exec "norm! GV6k2g\<C-A>"
+ call assert_equal(["12", "", "24", "", "36", "", "48"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+
+ call setline(1, ["10", "", "20", "", "30", "", "40"])
+ exec "norm! GV6k2g\<C-X>"
+ call assert_equal(["8", "", "16", "", "24", "", "32"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" Ctrl-A on non-number
+func Test_visual_increment_04()
+ call setline(1, ["foobar-10"])
+ exec "norm! vf-\<C-A>"
+ call assert_equal(["foobar-10"], getline(1, '$'))
+ call assert_equal([0, 1, 7, 0], getpos('.'))
+endfunc
+
+" g<Ctrl-A> on letter
+func Test_visual_increment_05()
+ set nrformats+=alpha
+ call setline(1, repeat(["a"], 4))
+ exec "norm! GV3kg\<C-A>"
+ call assert_equal(["b", "c", "d", "e"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" g<Ctrl-X> on letter
+func Test_visual_increment_06()
+ set nrformats+=alpha
+ call setline(1, repeat(["z"], 4))
+ exec "norm! GV3kg\<C-X>"
+ call assert_equal(["y", "x", "w", "v"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" <Ctrl-A> on letter
+func Test_visual_increment_07()
+ call setline(1, ["2", "1", "0", "-1", "-2"])
+ exec "norm! GV4k\<C-A>"
+ call assert_equal(["3", "2", "1", "0", "-1"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+
+ call setline(1, ["2", "1", "0", "-1", "-2"])
+ exec "norm! GV4k\<C-X>"
+ call assert_equal(["1", "0", "-1", "-2", "-3"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" Block increment on 0x9
+func Test_visual_increment_08()
+ call setline(1, repeat(["0x9"], 2))
+ exec "norm! \<C-V>j$\<C-A>"
+ call assert_equal(["0xa", "0xa"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+
+ call setline(1, repeat(["0x9"], 2))
+ exec "norm! gg$\<C-V>+\<C-A>"
+ call assert_equal(["0xa", "0xa"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" Increment and redo
+func Test_visual_increment_09()
+ call setline(1, ["2", "2", "", "3", "3", ""])
+ exec "norm! ggVj2\<C-A>3j."
+ call assert_equal(["4", "4", "", "5", "5", ""], getline(1, '$'))
+ call assert_equal([0, 4, 1, 0], getpos('.'))
+endfunc
+
+" sequentially decrement 1
+func Test_visual_increment_10()
+ call setline(1, repeat(["1"], 4))
+ exec "norm! GV3kg\<C-X>"
+ call assert_equal(["0", "-1", "-2", "-3"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" visually block selected indented lines
+func Test_visual_increment_11()
+ call setline(1, [" 1", "1", " 1", " 1"])
+ exec "norm! f1\<C-V>3jg\<C-A>"
+ call assert_equal([" 2", "1", " 3", " 4"], getline(1, '$'))
+ call assert_equal([0, 1, 5, 0], getpos('.'))
+endfunc
+
+" visually selected several columns
+func Test_visual_increment_12()
+ call setline(1, repeat(["0 0"], 3))
+ exec "norm! $v++\<C-A>"
+ call assert_equal(["0 1", "1 0", "1 0"], getline(1, '$'))
+ call assert_equal([0, 1, 3, 0], getpos('.'))
+endfunc
+
+" visually selected part of columns
+func Test_visual_increment_13()
+ call setline(1, ["max: 100px", "max: 200px", "max: 300px", "max: 400px"])
+ exec "norm! f1\<C-V>l2j\<C-A>"
+ call assert_equal(["max: 110px", "max: 210px", "max: 310px", "max: 400px"],
+ \ getline(1, '$'))
+ call assert_equal([0, 1, 6, 0], getpos('.'))
+
+ call setline(1, ["max: 100px", "max: 200px", "max: 300px", "max: 400px"])
+ exec "norm! ggf1\<C-V>l2j\<C-X>"
+ call assert_equal(["max: 90px", "max: 190px", "max: 290px", "max: 400px"],
+ \ getline(1, '$'))
+ call assert_equal([0, 1, 6, 0], getpos('.'))
+endfunc
+
+" redo in block mode
+func Test_visual_increment_14()
+ call setline(1, repeat(["1 1"], 2))
+ exec "norm! G\<C-V>k\<C-A>w."
+ call assert_equal(["2 2", "2 2"], getline(1, '$'))
+ call assert_equal([0, 1, 3, 0], getpos('.'))
+endfunc
+
+" block select single numbers
+func Test_visual_increment_15()
+ call setline(1, ["101"])
+ exec "norm! lv\<C-A>"
+ call assert_equal(["111"], getline(1, '$'))
+ call assert_equal([0, 1, 2, 0], getpos('.'))
+endfunc
+
+" increment right aligned numbers
+func Test_visual_increment_16()
+ call setline(1, [" 1", " 19", " 119"])
+ exec "norm! VG\<C-A>"
+ call assert_equal([" 2", " 20", " 120"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" block-wise increment and redo
+func Test_visual_increment_17()
+ call setline(1, [" 100", " 1", "", " 100", " 1"])
+ exec "norm! \<C-V>j$\<C-A>2j."
+ call assert_equal([" 101", " 2", "", " 101", " 1"], getline(1, '$'))
+ call assert_equal([0, 3, 1, 0], getpos('.'))
+endfunc
+
+" repeat of g<Ctrl-a>
+func Test_visual_increment_18()
+ call setline(1, repeat(["0"], 4))
+ exec "norm! GV3kg\<C-A>.."
+ call assert_equal(["3", "6", "9", "12"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" increment on number with nrformat including alpha
+func Test_visual_increment_19()
+ set nrformats+=alpha
+ call setline(1, ["1", "1a"])
+ exec "norm! \<C-V>G$\<C-A>"
+ call assert_equal(["2", "2a"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" increment a single letter
+func Test_visual_increment_20()
+ set nrformats+=alpha
+ call setline(1, ["a"])
+ exec "norm! \<C-A>"
+ call assert_equal(["b"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" block-wise increment on part of hexadecimal
+func Test_visual_increment_21()
+ call setline(1, ["0x123456"])
+ exec "norm! \<C-V>f3\<C-A>"
+ call assert_equal(["0x124456"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" Tab code and linewise-visual inc/dec
+func Test_visual_increment_22()
+ call setline(1, ["x\<TAB>10", "\<TAB>-1"])
+ exec "norm! Vj\<C-A>"
+ call assert_equal(["x\<TAB>11", "\<TAB>0"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+
+ call setline(1, ["x\<TAB>10", "\<TAB>-1"])
+ exec "norm! ggVj\<C-X>"
+ call assert_equal(["x\<TAB>9", "\<TAB>-2"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" Tab code and linewise-visual inc/dec with 'nrformats'+=alpha
+func Test_visual_increment_23()
+ set nrformats+=alpha
+ call setline(1, ["x\<TAB>10", "\<TAB>-1"])
+ exec "norm! Vj\<C-A>"
+ call assert_equal(["y\<TAB>10", "\<TAB>0"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+
+ call setline(1, ["x\<TAB>10", "\<TAB>-1"])
+ exec "norm! ggVj\<C-X>"
+ call assert_equal(["w\<TAB>10", "\<TAB>-2"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" Tab code and character-visual inc/dec
+func Test_visual_increment_24()
+ call setline(1, ["x\<TAB>10", "\<TAB>-1"])
+ exec "norm! f1vjf1\<C-A>"
+ call assert_equal(["x\<TAB>11", "\<TAB>0"], getline(1, '$'))
+ call assert_equal([0, 1, 3, 0], getpos('.'))
+
+ call setline(1, ["x\<TAB>10", "\<TAB>-1"])
+ exec "norm! ggf1vjf1\<C-X>"
+ call assert_equal(["x\<TAB>9", "\<TAB>-2"], getline(1, '$'))
+ call assert_equal([0, 1, 3, 0], getpos('.'))
+endfunc
+
+" Tab code and blockwise-visual inc/dec
+func Test_visual_increment_25()
+ call setline(1, ["x\<TAB>10", "\<TAB>-1"])
+ exec "norm! f1\<C-V>jl\<C-A>"
+ call assert_equal(["x\<TAB>11", "\<TAB>0"], getline(1, '$'))
+ call assert_equal([0, 1, 3, 0], getpos('.'))
+
+ call setline(1, ["x\<TAB>10", "\<TAB>-1"])
+ exec "norm! ggf1\<C-V>jl\<C-X>"
+ call assert_equal(["x\<TAB>9", "\<TAB>-2"], getline(1, '$'))
+ call assert_equal([0, 1, 3, 0], getpos('.'))
+endfunc
+
+" Tab code and blockwise-visual decrement with 'linebreak' and 'showbreak'
+func Test_visual_increment_26()
+ 28vnew
+ set linebreak showbreak=+
+ call setline(1, ["x\<TAB>\<TAB>\<TAB>10", "\<TAB>\<TAB>\<TAB>\<TAB>-1"])
+ exec "norm! ggf0\<C-V>jg_\<C-X>"
+ call assert_equal(["x\<TAB>\<TAB>\<TAB>1-1", "\<TAB>\<TAB>\<TAB>\<TAB>-2"],
+ \ getline(1, '$'))
+ call assert_equal([0, 1, 6, 0], getpos('.'))
+ bwipe!
+endfunc
+
+" Tab code and blockwise-visual increment with $
+func Test_visual_increment_27()
+ call setline(1, ["\<TAB>123", "456"])
+ exec "norm! gg0\<C-V>j$\<C-A>"
+ call assert_equal(["\<TAB>124", "457"], getline(1, '$'))
+ call assert_equal([0, 1, 1, 0], getpos('.'))
+endfunc
+
+" Tab code, spaces and character-visual increment and redo
+func Test_visual_increment_28()
+ call setline(1, ["\<TAB>123", " 123", "\<TAB>123", "\<TAB>123"])
+ exec "norm! ggvjf3\<C-A>..."
+ call assert_equal(["\<TAB>127", " 127", "\<TAB>123", "\<TAB>123"],
+ \ getline(1, '$'))
+ call assert_equal([0, 1, 2, 0], getpos('.'))
+endfunc
+
+" vim: tabstop=2 shiftwidth=2 expandtab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment