From 7790dca2ebf0afcc481b22f1b5ae5b5983c6ba19 Mon Sep 17 00:00:00 2001 From: varsidry <240319857+varsidry@users.noreply.github.com> Date: Sat, 1 Nov 2025 02:37:12 +0100 Subject: [PATCH] vim-patch:9.1.1891: g does not move to last non-blank in visual mode (#36354) Problem: In visual mode, g does not move to the last non-blank character when the end of a line is on the same line as the cursor (after v9.0.1753) Solution: Move the cursor back by one position if it lands after the line (varsidry) fixes: vim/vim#18657 closes: vim/vim#18658 https://github.com/vim/vim/commit/adc85151f3c6a6cea4bb8c8da3465429fc120445 (cherry picked from commit b92b95e2c26d5cea86acd3116ee029cc57676f14) --- runtime/doc/index.txt | 3 ++- src/nvim/normal.c | 2 +- test/old/testdir/test_normal.vim | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/runtime/doc/index.txt b/runtime/doc/index.txt index b814b3be78..9d9207d84c 100644 --- a/runtime/doc/index.txt +++ b/runtime/doc/index.txt @@ -790,7 +790,8 @@ tag char note action in Normal mode ~ |g@| g@{motion} call 'operatorfunc' |g~| g~{motion} 2 swap case for Nmove text |g| g 1 same as "gj" -|g| g 1 same as "g$" +|g| g 1 same as "g$" but go to the rightmost + non-blank character instead |g| g 1 same as "g0" |g| g same as g same as diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 7159575620..309f88428a 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -5360,7 +5360,7 @@ static void nv_g_dollar_cmd(cmdarg_T *cap) if (flag) { do { i = gchar_cursor(); - } while (ascii_iswhite(i) && oneleft() == OK); + } while (ascii_iswhite_or_nul(i) && oneleft() == OK); curwin->w_valid &= ~VALID_WCOL; } } diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim index 858d235233..5a0a8a0c33 100644 --- a/test/old/testdir/test_normal.vim +++ b/test/old/testdir/test_normal.vim @@ -4186,6 +4186,17 @@ func Test_normal33_g_cmd_nonblank() call assert_equal(20, col('.')) exe "normal 0g\" call assert_equal(11, col('.')) + + " Test visual mode at end of line + normal 0$bvg$y + call assert_equal(80, col("'>")) + exe "normal 0$bvg\y" + call assert_equal(71, col("'>")) + setlocal nowrap virtualedit=all + exe "normal 0$\llg\y" + call assert_equal(71, col("'<")) + exe "normal 0$llvg\y" + call assert_equal(71, col("'<")) bw! endfunc