Skip to content

Commit d048009

Browse files
committed
patch 8.0.1304: CTRL-G/CTRL-T don't work with incsearch and empty pattern
Problem: CTRL-G/CTRL-T don't work with incsearch and empty pattern. Solution: Use the last search pattern. (Christian Brabandt, closes #2292)
1 parent 9c6ce0e commit d048009

5 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/ex_getln.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ getcmdline(
220220
pos_T match_end;
221221
# ifdef FEAT_DIFF
222222
int old_topfill;
223-
int init_topfill = curwin->w_topfill;
223+
int init_topfill = curwin->w_topfill;
224224
# endif
225225
linenr_T old_botline;
226226
linenr_T init_botline = curwin->w_botline;
@@ -1715,11 +1715,17 @@ getcmdline(
17151715
if (p_is && !cmd_silent && (firstc == '/' || firstc == '?'))
17161716
{
17171717
pos_T t;
1718+
char_u *pat;
17181719
int search_flags = SEARCH_NOOF;
17191720

17201721
if (ccline.cmdlen == 0)
17211722
goto cmdline_not_changed;
17221723

1724+
if (firstc == ccline.cmdbuff[0])
1725+
pat = last_search_pattern();
1726+
else
1727+
pat = ccline.cmdbuff;
1728+
17231729
save_last_search_pattern();
17241730
cursor_off();
17251731
out_flush();
@@ -1739,7 +1745,7 @@ getcmdline(
17391745
++emsg_off;
17401746
i = searchit(curwin, curbuf, &t,
17411747
c == Ctrl_G ? FORWARD : BACKWARD,
1742-
ccline.cmdbuff, count, search_flags,
1748+
pat, count, search_flags,
17431749
RE_SEARCH, 0, NULL, NULL);
17441750
--emsg_off;
17451751
if (i)

src/proto/search.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ void save_search_patterns(void);
77
void restore_search_patterns(void);
88
void save_last_search_pattern(void);
99
void restore_last_search_pattern(void);
10+
char_u *last_search_pattern(void);
1011
void free_search_patterns(void);
1112
int ignorecase(char_u *pat);
1213
int ignorecase_opt(char_u *pat, int ic_in, int scs);

src/search.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,12 @@ restore_last_search_pattern(void)
393393
last_idx = saved_last_idx;
394394
SET_NO_HLSEARCH(saved_no_hlsearch);
395395
}
396+
397+
char_u *
398+
last_search_pattern(void)
399+
{
400+
return spats[RE_SEARCH].pat;
401+
}
396402
#endif
397403

398404
/*

src/testdir/test_search.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,15 @@ func Test_search_cmdline7()
461461
" moves to next match of previous search pattern, just like /<cr>
462462
call feedkeys("/\<c-t>\<cr>", 'tx')
463463
call assert_equal([0,1,7,0], getpos('.'))
464+
465+
" using an offset uses the last search pattern
466+
call cursor(1, 1)
467+
call setline(1, ['1 bbvimb', ' 2 bbvimb'])
468+
let @/ = 'b'
469+
call feedkeys("//e\<c-g>\<cr>", 'tx')
470+
call assert_equal('1 bbvimb', getline('.'))
471+
call assert_equal(4, col('.'))
472+
464473
set noincsearch
465474
call test_override("char_avail", 0)
466475
bw!

src/version.c

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

767767
static int included_patches[] =
768768
{ /* Add new patch number below this line */
769+
/**/
770+
1304,
769771
/**/
770772
1303,
771773
/**/

0 commit comments

Comments
 (0)