To reproduce, after vim --clean
:
//
to search again for the last searched pattern;Vim searches for a slash character instead of moving to the next/prev occurrence of the last searched pattern.
Using Vim 8.0.1250 on macOS.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
Here is a patch, that will make use of the last search pattern, if only the offset has been entered.
From cc87161aaafe93ffef19598f193ff680873124b7 Mon Sep 17 00:00:00 2001 From: Christian Brabandt <c...@256bit.org> Date: Mon, 13 Nov 2017 16:31:15 +0100 Subject: [PATCH] Use last search pattern, if no pattern is given When incsearch is used and <c-g> and <c-t> is used after entering only the offset, use the last search pattern. fixes #2292 --- src/ex_getln.c | 8 +++++++- src/proto/search.pro | 1 + src/search.c | 6 ++++++ src/testdir/test_search.vim | 9 +++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/ex_getln.c b/src/ex_getln.c index 5589cd82a..8b5419bcc 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -1715,11 +1715,17 @@ getcmdline( if (p_is && !cmd_silent && (firstc == '/' || firstc == '?')) { pos_T t; + char_u *pat; int search_flags = SEARCH_NOOF; if (ccline.cmdlen == 0) goto cmdline_not_changed; + if (firstc == ccline.cmdbuff[0]) + pat = last_search_pattern(); + else + pat = ccline.cmdbuff; + save_last_search_pattern(); cursor_off(); out_flush(); @@ -1739,7 +1745,7 @@ getcmdline( ++emsg_off; i = searchit(curwin, curbuf, &t, c == Ctrl_G ? FORWARD : BACKWARD, - ccline.cmdbuff, count, search_flags, + pat, count, search_flags, RE_SEARCH, 0, NULL, NULL); --emsg_off; if (i) diff --git a/src/proto/search.pro b/src/proto/search.pro index 41c200612..4e63bf31a 100644 --- a/src/proto/search.pro +++ b/src/proto/search.pro @@ -7,6 +7,7 @@ void save_search_patterns(void); void restore_search_patterns(void); void save_last_search_pattern(void); void restore_last_search_pattern(void); +char_u *last_search_pattern(void); void free_search_patterns(void); int ignorecase(char_u *pat); int ignorecase_opt(char_u *pat, int ic_in, int scs); diff --git a/src/search.c b/src/search.c index fc689db2d..8bb5f3d97 100644 --- a/src/search.c +++ b/src/search.c @@ -393,6 +393,12 @@ restore_last_search_pattern(void) last_idx = saved_last_idx; SET_NO_HLSEARCH(saved_no_hlsearch); } + + char_u * +last_search_pattern(void) +{ + return spats[RE_SEARCH].pat; +} #endif /* diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim index 2a660c61b..d13e65458 100644 --- a/src/testdir/test_search.vim +++ b/src/testdir/test_search.vim @@ -461,6 +461,15 @@ func Test_search_cmdline7() " moves to next match of previous search pattern, just like /<cr> call feedkeys("/\<c-t>\<cr>", 'tx') call assert_equal([0,1,7,0], getpos('.')) + + " using an offset uses the last search pattern + call cursor(1, 1) + call setline(1, ['1 bbvimb', ' 2 bbvimb']) + let @/ = 'b' + call feedkeys("//e\<c-g>\<cr>", 'tx') + call assert_equal('1 bbvimb', getline('.')) + call assert_equal(4, col('.')) + set noincsearch call test_override("char_avail", 0) bw! -- 2.14.1
I can confirm that the patch fixes the issue. Thanks!