-*options.txt* For Vim version 9.1. Last change: 2025 Mar 01
+*options.txt* For Vim version 9.1. Last change: 2025 Mar 02
VIM REFERENCE MANUAL by Bram Moolenaar
"lastused" When completing buffer names and more than one buffer
matches, sort buffers by time last used (other than
the current buffer).
- When there is only a single match, it is fully completed in all cases.
+ "noselect" Do not pre-select first menu item and start 'wildmenu'
+ if it is enabled.
+ When there is only a single match, it is fully completed in all cases
+ except when "noselect" is present.
Examples of useful colon-separated values:
"longest:full" Like "longest", but also start 'wildmenu' if it is
:set wildmode=list,full
< List all matches without completing, then each full match >
:set wildmode=longest,list
-< Complete longest common string, then list alternatives.
+< Complete longest common string, then list alternatives >
+ :set wildmode=noselect:full
+< Display 'wildmenu' without completing, then each full match >
+ :set wildmode=noselect:lastused,full
+< Same as above, but sort buffers by time last used.
More info here: |cmdline-completion|.
*'wildoptions'* *'wop'*
-*version9.txt* For Vim version 9.1. Last change: 2025 Feb 23
+*version9.txt* For Vim version 9.1. Last change: 2025 Mar 02
VIM REFERENCE MANUAL by Bram Moolenaar
"preinsert" - highlight to be inserted values
- handle multi-line completion as expected
- improved commandline completion for the |:hi| command
+- New option value for 'wildoptions':
+ "noselect" - do not auto select an entry in the wildmenu
Options: ~
- the default for 'commentstring' contains whitespace padding to have
{
int use_options = options |
WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT;
+ if (use_options & WILD_KEEP_SOLE_ITEM)
+ use_options &= ~WILD_KEEP_SOLE_ITEM;
+
if (escape)
use_options |= WILD_ESCAPE;
if (xp->xp_numfiles <= 0 && p2 == NULL)
beep_flush();
- else if (xp->xp_numfiles == 1)
+ else if (xp->xp_numfiles == 1 && !(options & WILD_KEEP_SOLE_ITEM))
// free expanded pattern
(void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE);
if (wim_flags[wim_index] & WIM_BUFLASTUSED)
options |= WILD_BUFLASTUSED;
+ if (wim_flags[0] & WIM_NOSELECT)
+ options |= WILD_KEEP_SOLE_ITEM;
if (xp->xp_numfiles > 0) // typed p_wc at least twice
{
// if 'wildmode' contains "list" may still need to list
// when more than one match, and 'wildmode' first contains
// "list", or no change and 'wildmode' contains "longest,list",
// list all matches
- if (res == OK && xp->xp_numfiles > 1)
+ if (res == OK
+ && xp->xp_numfiles > ((wim_flags[wim_index] & WIM_NOSELECT) ? 0 : 1))
{
// a "longest" that didn't do anything is skipped (but not
// "list:longest")
if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j)
wim_index = 1;
if ((wim_flags[wim_index] & WIM_LIST)
- || (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0))
+ || (p_wmnu && (wim_flags[wim_index] & (WIM_FULL | WIM_NOSELECT))))
{
if (!(wim_flags[0] & WIM_LONGEST))
{
p_wmnu = 0;
// remove match
- nextwild(xp, WILD_PREV, 0, escape);
+ nextwild(xp, WILD_PREV, 0 | (options & ~WIM_NOSELECT), escape);
p_wmnu = p_wmnu_save;
}
(void)showmatches(xp, p_wmnu
*did_wild_list = TRUE;
if (wim_flags[wim_index] & WIM_LONGEST)
nextwild(xp, WILD_LONGEST, options, escape);
- else if (wim_flags[wim_index] & WIM_FULL)
+ else if ((wim_flags[wim_index] & WIM_FULL)
+ && !(wim_flags[wim_index] & WIM_NOSELECT))
nextwild(xp, WILD_NEXT, options, escape);
}
else
new_wim_flags[idx] |= WIM_LIST;
else if (i == 8 && STRNCMP(p, "lastused", 8) == 0)
new_wim_flags[idx] |= WIM_BUFLASTUSED;
+ else if (i == 8 && STRNCMP(p, "noselect", 8) == 0)
+ new_wim_flags[idx] |= WIM_NOSELECT;
else
return FAIL;
p += i;
#define WIM_LONGEST 0x02
#define WIM_LIST 0x04
#define WIM_BUFLASTUSED 0x08
+#define WIM_NOSELECT 0x10
// flags for the 'wildoptions' option
// each defined char should be unique over all values.
#endif
static char *(p_ve_values[]) = {"block", "insert", "all", "onemore", "none", "NONE", NULL};
// Note: Keep this in sync with check_opt_wim()
-static char *(p_wim_values[]) = {"full", "longest", "list", "lastused", NULL};
+static char *(p_wim_values[]) = {"full", "longest", "list", "lastused", "noselect", NULL};
static char *(p_wop_values[]) = {"fuzzy", "tagfile", "pum", NULL};
#ifdef FEAT_WAK
static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
\ 'bs'],
\ ['xxx']],
\ 'wildmode': [['', 'full', 'longest', 'list', 'lastused', 'list:full',
+ \ 'noselect', 'noselect,full', 'noselect:lastused,full',
\ 'full,longest', 'full,full,full,full'],
\ ['xxx', 'a4', 'full,full,full,full,full']],
\ 'wildoptions': [['', 'tagfile', 'pum', 'fuzzy'], ['xxx']],
call assert_equal('AAA AAAA AAAAA', g:Sline)
call assert_equal('"b A', @:)
+ " When 'wildmenu' is not set, 'noselect' completes first item
+ set wildmode=noselect
+ call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd oneA', @:)
+
+ " When 'noselect' is present, do not complete first <tab>.
+ set wildmenu
+ set wildmode=noselect
+ call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd o', @:)
+ call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd o', @:)
+ call feedkeys(":MyCmd o\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd o', @:)
+
+ " When 'full' is present, complete after first <tab>.
+ set wildmode=noselect,full
+ call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd o', @:)
+ call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd oneA', @:)
+ call feedkeys(":MyCmd o\t\t\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd oneB', @:)
+ call feedkeys(":MyCmd o\t\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd oneB', @:)
+
+ " 'noselect' has no effect when 'longest' is present.
+ set wildmode=noselect:longest
+ call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd one', @:)
+
+ " Complete 'noselect' value in 'wildmode' option
+ set wildmode&
+ call feedkeys(":set wildmode=n\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"set wildmode=noselect', @:)
+ call feedkeys(":set wildmode=\t\t\t\t\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"set wildmode=noselect', @:)
+
" when using longest completion match, matches shorter than the argument
" should be ignored (happens with :help)
set wildmode=longest,full
- set wildmenu
call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
call assert_equal('"help a', @:)
" non existing file
call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
call assert_equal('"e a1b2y3z4', @:)
- set wildmenu&
" Test for longest file name completion with 'fileignorecase'
" On MS-Windows, file names are case insensitive.
set fileignorecase&
endif
+ " If 'noselect' is present, single item menu should not insert item
+ func! T(a, c, p)
+ return "oneA"
+ endfunc
+ command! -nargs=1 -complete=custom,T MyCmd
+ set wildmode=noselect,full
+ call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd o', @:)
+ call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd oneA', @:)
+ " 'nowildmenu' should make 'noselect' ineffective
+ set nowildmenu
+ call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
+ call assert_equal('"MyCmd oneA', @:)
+
%argdelete
delcommand MyCmd
delfunc T
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1166,
/**/
1165,
/**/
#define WILD_NOERROR 0x800 // sets EW_NOERROR
#define WILD_BUFLASTUSED 0x1000
#define BUF_DIFF_FILTER 0x2000
+#define WILD_KEEP_SOLE_ITEM 0x4000
// Flags for expand_wildcards()
#define EW_DIR 0x01 // include directory names