patch 8.1.2231: not easy to move to the middle of a text line
Problem: Not easy to move to the middle of a text line.
Solution: Add the gM command. (Yasuhiro Matsumoto, closes #2070)
diff --git a/src/normal.c b/src/normal.c
index f66a97c..17db06a 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -5979,6 +5979,24 @@
curwin->w_set_curswant = TRUE;
break;
+ case 'M':
+ {
+ char_u *ptr = ml_get_curline();
+
+ oap->motion_type = MCHAR;
+ oap->inclusive = FALSE;
+ if (has_mbyte)
+ i = mb_string2cells(ptr, STRLEN(ptr));
+ else
+ i = (int)STRLEN(ptr);
+ if (cap->count0 > 0 && cap->count0 <= 100)
+ coladvance((colnr_T)(i * cap->count0 / 100));
+ else
+ coladvance((colnr_T)(i / 2));
+ curwin->w_set_curswant = TRUE;
+ }
+ break;
+
case '_':
/* "g_": to the last non-blank character in the line or <count> lines
* downward. */
diff --git a/src/testdir/test_normal.vim b/src/testdir/test_normal.vim
index b37f613..c4b38b1 100644
--- a/src/testdir/test_normal.vim
+++ b/src/testdir/test_normal.vim
@@ -1733,6 +1733,7 @@
set wrap listchars= sbr=
let lineA='abcdefghijklmnopqrstuvwxyz'
let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
$put =lineA
$put =lineB
@@ -1766,9 +1767,30 @@
call assert_equal(15, col('.'))
call assert_equal('l', getreg(0))
+ norm! 2ggdd
+ $put =lineC
+
+ " Test for gM
+ norm! gMyl
+ call assert_equal(73, col('.'))
+ call assert_equal('0', getreg(0))
+ " Test for 20gM
+ norm! 20gMyl
+ call assert_equal(29, col('.'))
+ call assert_equal('S', getreg(0))
+ " Test for 60gM
+ norm! 60gMyl
+ call assert_equal(87, col('.'))
+ call assert_equal('E', getreg(0))
+
+ " Test for g Ctrl-G
+ set ff=unix
+ let a=execute(":norm! g\<c-g>")
+ call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
+
" Test for gI
norm! gIfoo
- call assert_equal(['', 'fooabcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
+ call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
" Test for gi
wincmd c
diff --git a/src/version.c b/src/version.c
index 07a8cd9..99f1570 100644
--- a/src/version.c
+++ b/src/version.c
@@ -742,6 +742,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2231,
+/**/
2230,
/**/
2229,