aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/cmdexpand.c4
-rw-r--r--src/nvim/cmdexpand.h1
-rw-r--r--src/nvim/ex_getln.c15
-rw-r--r--src/nvim/options.lua13
4 files changed, 24 insertions, 9 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c
index 33ccc834d2..fcfeda5482 100644
--- a/src/nvim/cmdexpand.c
+++ b/src/nvim/cmdexpand.c
@@ -288,7 +288,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape)
p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context);
}
// Translate string into pattern and expand it.
- const int use_options = (options
+ const int use_options = ((options & ~WILD_KEEP_SOLE_ITEM)
| WILD_HOME_REPLACE
| WILD_ADD_SLASH
| WILD_SILENT
@@ -339,7 +339,7 @@ int nextwild(expand_T *xp, int type, int options, bool 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
ExpandOne(xp, NULL, NULL, 0, WILD_FREE);
}
diff --git a/src/nvim/cmdexpand.h b/src/nvim/cmdexpand.h
index 33ff787589..59c734e9a3 100644
--- a/src/nvim/cmdexpand.h
+++ b/src/nvim/cmdexpand.h
@@ -40,6 +40,7 @@ enum {
WILD_NOERROR = 0x800, ///< sets EW_NOERROR
WILD_BUFLASTUSED = 0x1000,
BUF_DIFF_FILTER = 0x2000,
+ WILD_KEEP_SOLE_ITEM = 0x4000,
};
#ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index fc20748309..240bdae6cb 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -1082,6 +1082,9 @@ static int command_line_wildchar_complete(CommandLineState *s)
if (wim_flags[s->wim_index] & kOptWimFlagLastused) {
options |= WILD_BUFLASTUSED;
}
+ if (wim_flags[0] & kOptWimFlagNoselect) {
+ options |= WILD_KEEP_SOLE_ITEM;
+ }
if (s->xpc.xp_numfiles > 0) { // typed p_wc at least twice
// if 'wildmode' contains "list" may still need to list
if (s->xpc.xp_numfiles > 1
@@ -1124,19 +1127,20 @@ static int command_line_wildchar_complete(CommandLineState *s)
// when more than one match, and 'wildmode' first contains
// "list", or no change and 'wildmode' contains "longest,list",
// list all matches
- if (res == OK && s->xpc.xp_numfiles > 1) {
+ if (res == OK
+ && s->xpc.xp_numfiles > ((wim_flags[s->wim_index] & kOptWimFlagNoselect) ? 0 : 1)) {
// a "longest" that didn't do anything is skipped (but not
// "list:longest")
if (wim_flags[0] == kOptWimFlagLongest && ccline.cmdpos == j) {
s->wim_index = 1;
}
if ((wim_flags[s->wim_index] & kOptWimFlagList)
- || (p_wmnu && (wim_flags[s->wim_index] & kOptWimFlagFull) != 0)) {
+ || (p_wmnu && (wim_flags[s->wim_index] & (kOptWimFlagFull|kOptWimFlagNoselect)))) {
if (!(wim_flags[0] & kOptWimFlagLongest)) {
int p_wmnu_save = p_wmnu;
p_wmnu = 0;
// remove match
- nextwild(&s->xpc, WILD_PREV, 0, s->firstc != '@');
+ nextwild(&s->xpc, WILD_PREV, options, s->firstc != '@');
p_wmnu = p_wmnu_save;
}
@@ -1146,7 +1150,8 @@ static int command_line_wildchar_complete(CommandLineState *s)
if (wim_flags[s->wim_index] & kOptWimFlagLongest) {
nextwild(&s->xpc, WILD_LONGEST, options, s->firstc != '@');
- } else if (wim_flags[s->wim_index] & kOptWimFlagFull) {
+ } else if ((wim_flags[s->wim_index] & kOptWimFlagFull)
+ && !(wim_flags[s->wim_index] & kOptWimFlagNoselect)) {
nextwild(&s->xpc, WILD_NEXT, options, s->firstc != '@');
}
} else {
@@ -2875,6 +2880,8 @@ int check_opt_wim(void)
new_wim_flags[idx] |= kOptWimFlagList;
} else if (i == 8 && strncmp(p, "lastused", 8) == 0) {
new_wim_flags[idx] |= kOptWimFlagLastused;
+ } else if (i == 8 && strncmp(p, "noselect", 8) == 0) {
+ new_wim_flags[idx] |= kOptWimFlagNoselect;
} else {
return FAIL;
}
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index d1d5a56082..2516d1a970 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -10020,7 +10020,7 @@ local options = {
cb = 'did_set_wildmode',
defaults = 'full',
-- Keep this in sync with check_opt_wim().
- values = { 'full', 'longest', 'list', 'lastused' },
+ values = { 'full', 'longest', 'list', 'lastused', 'noselect' },
flags = true,
deny_duplicates = false,
desc = [=[
@@ -10042,7 +10042,10 @@ local options = {
"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
@@ -10065,7 +10068,11 @@ local options = {
set wildmode=list,full
< List all matches without completing, then each full match >vim
set wildmode=longest,list
- < Complete longest common string, then list alternatives.
+ < Complete longest common string, then list alternatives >vim
+ set wildmode=noselect:full
+ < Display 'wildmenu' without completing, then each full match >vim
+ set wildmode=noselect:lastused,full
+ < Same as above, but sort buffers by time last used.
More info here: |cmdline-completion|.
]=],
full_name = 'wildmode',