Skip to content

Commit 453c192

Browse files
committed
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, #5075)
1 parent c7488a7 commit 453c192

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/search.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4677,7 +4677,7 @@ current_quote(
46774677
#endif /* FEAT_TEXTOBJ */
46784678

46794679
/*
4680-
* Check if the pattern is one character long or zero-width.
4680+
* Check if the pattern is zero-width.
46814681
* If move is TRUE, check from the beginning of the buffer, else from position
46824682
* "cur".
46834683
* "direction" is FORWARD or BACKWARD.
@@ -4851,7 +4851,7 @@ current_search(
48514851

48524852
// put cursor on last character of match
48534853
curwin->w_cursor = end_pos;
4854-
if (LT_POS(VIsual, end_pos))
4854+
if (LT_POS(VIsual, end_pos) && forward)
48554855
dec_cursor();
48564856
else if (VIsual_active && LT_POS(curwin->w_cursor, VIsual))
48574857
curwin->w_cursor = pos; // put the cursor on the start of the match

src/testdir/test_gn.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ func Test_gn_command()
148148
norm! gg0f7vhhhhgnd
149149
call assert_equal(['12348'], getline(1,'$'))
150150
sil! %d _
151+
call setline('.', ['12345678'])
152+
let @/ = '5'
153+
norm! gg0f2vf7gNd
154+
call assert_equal(['1678'], getline(1,'$'))
155+
sil! %d _
151156

152157
set wrapscan&vim
153158
endfu

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
2218,
744746
/**/
745747
2217,
746748
/**/

0 commit comments

Comments
 (0)