Skip to content

Commit 708ab7f

Browse files
girishjichrisbra
authored andcommitted
patch 9.1.1738: cmdline-autocompletion breaks history navigation
Problem: cmdline-autocompletion breaks history navigation (ddad431) Solution: Support history navigation in cmdline autocompletion (Girish Palya) Up/Down arrows support history navigation when using wildtrigger() fixes: #18207 closes: #18219 Signed-off-by: Girish Palya <girishji@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 8fec92d commit 708ab7f

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

runtime/doc/builtin.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*builtin.txt* For Vim version 9.1. Last change: 2025 Sep 02
1+
*builtin.txt* For Vim version 9.1. Last change: 2025 Sep 06
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -12416,18 +12416,19 @@ wildtrigger() *wildtrigger()*
1241612416
produce a beep when no matches are found and generally
1241712417
operates more quietly. This makes it suitable for triggering
1241812418
completion automatically, such as from an |:autocmd|.
12419+
1241912420
*cmdline-autocompletion*
12420-
Example: To make the completion menu pop up automatically as
12421-
you type on the command line, use: >
12421+
Example: To make the completion menu pop up automatically
12422+
while typing on the command line: >
1242212423
autocmd CmdlineChanged [:/\?] call wildtrigger()
1242312424
set wildmode=noselect:lastused,full wildoptions=pum
1242412425
<
12425-
To retain normal history navigation (up/down keys): >
12426-
cnoremap <Up> <C-U><Up>
12427-
cnoremap <Down> <C-U><Down>
12426+
To retain normal history navigation with the up/down keys: >
12427+
cnoremap <expr> <Up> wildmenumode() ? "\<C-E>\<Up>" : "\<Up>"
12428+
cnoremap <expr> <Down> wildmenumode() ? "\<C-E>\<Down>" : "\<Down>"
1242812429
<
12429-
To set an option specifically when performing a search, e.g.
12430-
to set 'pumheight': >
12430+
To apply an option only during a search, for example to set
12431+
'pumheight': >
1243112432
autocmd CmdlineEnter [/\?] set pumheight=8
1243212433
autocmd CmdlineLeave [/\?] set pumheight&
1243312434
<

src/ex_getln.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,7 @@ getcmdline_int(
16811681
int wild_type = 0;
16821682
int event_cmdlineleavepre_triggered = FALSE;
16831683
char_u *prev_cmdbuff = NULL;
1684+
int did_hist_navigate = FALSE;
16841685

16851686
// one recursion level deeper
16861687
++depth;
@@ -1891,6 +1892,13 @@ getcmdline_int(
18911892
c = safe_vgetc();
18921893
} while (c == K_IGNORE || c == K_NOP);
18931894

1895+
// Skip wildmenu during history navigation via Up/Down keys
1896+
if (c == K_WILD && did_hist_navigate)
1897+
{
1898+
did_hist_navigate = FALSE;
1899+
continue;
1900+
}
1901+
18941902
if (c == K_COMMAND || c == K_SCRIPT_COMMAND)
18951903
{
18961904
int clen = ccline.cmdlen;
@@ -2489,7 +2497,10 @@ getcmdline_int(
24892497
res = cmdline_browse_history(c, firstc, &lookfor, &lookforlen, histype,
24902498
&hiscnt, &xpc);
24912499
if (res == CMDLINE_CHANGED)
2500+
{
2501+
did_hist_navigate = TRUE;
24922502
goto cmdline_changed;
2503+
}
24932504
else if (res == GOTO_NORMAL_MODE)
24942505
goto returncmd;
24952506
}

src/testdir/test_cmdline.vim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5039,4 +5039,28 @@ func Test_CmdlineLeave_vchar_keys()
50395039
unlet g:leave_key
50405040
endfunc
50415041

5042+
" Skip wildmenu during history navigation via Up/Down keys
5043+
func Test_skip_wildtrigger_hist_navigation()
5044+
call test_override("char_avail", 1)
5045+
cnoremap <F8> <C-R>=wildtrigger()[-1]<CR>
5046+
set wildmenu
5047+
5048+
call feedkeys(":ech\<F8>\<F4>\<C-B>\"\<CR>", "tx")
5049+
call assert_match('echo*', g:Sline)
5050+
call assert_equal('"echo', @:)
5051+
5052+
call feedkeys(":echom \"foo\"", "tx")
5053+
call feedkeys(":echom \"foobar\"", "tx")
5054+
call feedkeys(":ech\<F8>\<C-E>\<UP>\<C-B>\"\<CR>", "tx")
5055+
call assert_equal('"echom "foobar"', @:)
5056+
call feedkeys(":ech\<F8>\<C-E>\<UP>\<UP>\<UP>\<C-B>\"\<CR>", "tx")
5057+
call assert_equal('"echom "foo"', @:)
5058+
call feedkeys(":ech\<F8>\<C-E>\<UP>\<UP>\<UP>\<Down>\<C-B>\"\<CR>", "tx")
5059+
call assert_equal('"echom "foobar"', @:)
5060+
5061+
call test_override("char_avail", 0)
5062+
set wildmenu&
5063+
cunmap <F8>
5064+
endfunc
5065+
50425066
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

725725
static int included_patches[] =
726726
{ /* Add new patch number below this line */
727+
/**/
728+
1738,
727729
/**/
728730
1737,
729731
/**/

0 commit comments

Comments
 (0)