[vim/vim] Perhaps a bug with searching forward with a negative offset (Issue #17993)

5 views
Skip to first unread message

lkintact

unread,
Aug 13, 2025, 8:19:01 PMAug 13
to vim/vim, Subscribed
lkintact created an issue (vim/vim#17993)

Steps to reproduce

  1. Run gvim.exe --clean.
  2. Copy this text into the buffer:
1
2
3
aaa
5
6
aaa
7
  1. Type /aaa/-1 and press Enter. gVim moves to line 3 (expected), but for some reason changes the command line to /aaa/+-1 (probably a bug).
  2. Press n to move forward to the next search. Nothing happens (also probably a bug).

Expected behaviour

.

Version of Vim

9.1.1627

Environment

OS: Windows 10 Home 22H2,
Terminal: GUI.

Logs and stack traces


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/17993@github.com>

zeertzjq

unread,
Aug 13, 2025, 8:36:59 PMAug 13
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#17993)

This seems to fix the + problem:

diff --git a/src/search.c b/src/search.c
index 9a6bb3fbd..b9fbf19d1 100644
--- a/src/search.c
+++ b/src/search.c
@@ -1453,7 +1453,7 @@ do_search(
 		    off_buf[off_len++] = 'e';
 		else if (!spats[0].off.line)
 		    off_buf[off_len++] = 's';
-		if (spats[0].off.off > 0 || spats[0].off.line)
+		if (spats[0].off.off > 0)
 		    off_buf[off_len++] = '+';
 		off_buf[off_len] = NUL;
 		if (spats[0].off.off != 0 || spats[0].off.line)
  1. Press n to move forward to the next match. Nothing happens (also probably a bug).

I think this is working as intended, as the next match is still on line 4, so cursor remains on line 3.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/17993/3186277970@github.com>

zeertzjq

unread,
Aug 13, 2025, 8:50:08 PMAug 13
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#17993)

Or perhaps this is better:

diff --git a/src/search.c b/src/search.c
index 9a6bb3fbd..31b7d1934 100644
--- a/src/search.c
+++ b/src/search.c
@@ -1453,11 +1453,9 @@ do_search(
 		    off_buf[off_len++] = 'e';
 		else if (!spats[0].off.line)
 		    off_buf[off_len++] = 's';
-		if (spats[0].off.off > 0 || spats[0].off.line)
-		    off_buf[off_len++] = '+';
 		off_buf[off_len] = NUL;
 		if (spats[0].off.off != 0 || spats[0].off.line)
-		    off_len += vim_snprintf((char *)off_buf + off_len, sizeof(off_buf) - off_len, "%ld", spats[0].off.off);
+		    off_len += vim_snprintf((char *)off_buf + off_len, sizeof(off_buf) - off_len, "%+ld", spats[0].off.off);
 	    }
 
 	    if (*searchstr == NUL)


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/17993/3186301306@github.com>

Christian Brabandt

unread,
Aug 14, 2025, 3:22:26 PMAug 14
to vim/vim, Subscribed

Closed #17993 as completed via ade0815.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/17993/issue_event/19165605216@github.com>

Reply all
Reply to author
Forward
0 new messages