# HG changeset patch # User Bram Moolenaar # Date 1572093903 -7200 # Node ID 35e0ab1f29756c44fe16037eaa49bfb4796c3895 # Parent d978101d8bfd3057a38ff2aa25dd72580dbc7b52 patch 8.1.2218: "gN" is off by one in Visual mode Commit: https://github.com/vim/vim/commit/453c19257f6d97904ec2e3823e88e63c983f2f9a Author: Bram Moolenaar Date: Sat Oct 26 14:42:09 2019 +0200 patch 8.1.2218: "gN" is off by one in Visual mode Problem: "gN" is off by one in Visual mode. Solution: Check moving forward. (Christian Brabandt, https://github.com/vim/vim/issues/5075) diff --git a/src/search.c b/src/search.c --- a/src/search.c +++ b/src/search.c @@ -4677,7 +4677,7 @@ abort_search: #endif /* FEAT_TEXTOBJ */ /* - * Check if the pattern is one character long or zero-width. + * Check if the pattern is zero-width. * If move is TRUE, check from the beginning of the buffer, else from position * "cur". * "direction" is FORWARD or BACKWARD. @@ -4851,7 +4851,7 @@ current_search( // put cursor on last character of match curwin->w_cursor = end_pos; - if (LT_POS(VIsual, end_pos)) + if (LT_POS(VIsual, end_pos) && forward) dec_cursor(); else if (VIsual_active && LT_POS(curwin->w_cursor, VIsual)) curwin->w_cursor = pos; // put the cursor on the start of the match diff --git a/src/testdir/test_gn.vim b/src/testdir/test_gn.vim --- a/src/testdir/test_gn.vim +++ b/src/testdir/test_gn.vim @@ -148,6 +148,11 @@ func Test_gn_command() norm! gg0f7vhhhhgnd call assert_equal(['12348'], getline(1,'$')) sil! %d _ + call setline('.', ['12345678']) + let @/ = '5' + norm! gg0f2vf7gNd + call assert_equal(['1678'], getline(1,'$')) + sil! %d _ set wrapscan&vim endfu diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -742,6 +742,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2218, +/**/ 2217, /**/ 2216,