changeset 26749:efe4c8a79502 v8.2.3903

patch 8.2.3903: "gM" does not count tabs as expected Commit: https://github.com/vim/vim/commit/71c41255f6a074c4df4dc6f9e97d347e565253a1 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Dec 26 15:00:07 2021 +0000 patch 8.2.3903: "gM" does not count tabs as expected Problem: "gM" does not count tabs as expected. Solution: Use linetabsize() instead of mb_string2cells(). (closes https://github.com/vim/vim/issues/9409)
author Bram Moolenaar <Bram@vim.org>
date Sun, 26 Dec 2021 16:15:04 +0100
parents 36525b90ce11
children 2234a1c24680
files src/normal.c src/testdir/test_normal.vim src/version.c
diffstat 3 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/normal.c
+++ b/src/normal.c
@@ -6122,14 +6122,9 @@ nv_g_cmd(cmdarg_T *cap)
 
     case 'M':
 	{
-	    char_u  *ptr = ml_get_curline();
-
 	    oap->motion_type = MCHAR;
 	    oap->inclusive = FALSE;
-	    if (has_mbyte)
-		i = mb_string2cells(ptr, (int)STRLEN(ptr));
-	    else
-		i = (int)STRLEN(ptr);
+	    i = linetabsize(ml_get_curline());
 	    if (cap->count0 > 0 && cap->count0 <= 100)
 		coladvance((colnr_T)(i * cap->count0 / 100));
 	    else
--- a/src/testdir/test_normal.vim
+++ b/src/testdir/test_normal.vim
@@ -2580,7 +2580,15 @@ func Test_normal33_g_cmd2()
   call assert_equal(87, col('.'))
   call assert_equal('E', getreg(0))
 
+  " Test for gM with Tab characters
+  call setline('.', "\ta\tb\tc\td\te\tf")
+  norm! gMyl
+  call assert_equal(6, col('.'))
+  call assert_equal("c", getreg(0))
+
   " Test for g Ctrl-G
+  call setline('.', lineC)
+  norm! 60gMyl
   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)
--- a/src/version.c
+++ b/src/version.c
@@ -750,6 +750,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3903,
+/**/
     3902,
 /**/
     3901,