Skip to content

Commit a7b8120

Browse files
ychinchrisbra
authored andcommitted
patch 9.1.1138: cmdline completion for :hi is too simplistic
Problem: Existing cmdline completion for :highlight was barebone and only completed the highlight group names. Solution: Implement full completion for the highlight group arguments such as guifg and cterm. If the user tries to complete immediately after the '=' (e.g. `hi Normal guifg=<Tab>`), the completion will fill in the existing value, similar to how cmdline completion for options work (Yee Cheng Chin). closes: #16712 Signed-off-by: Yee Cheng Chin <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent f4b3641 commit a7b8120

File tree

12 files changed

+614
-76
lines changed

12 files changed

+614
-76
lines changed

runtime/doc/eval.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 9.1. Last change: 2025 Jan 29
1+
*eval.txt* For Vim version 9.1. Last change: 2025 Feb 23
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2081,7 +2081,7 @@ v:colornames A dictionary that maps color names to hex color strings. These
20812081

20822082
You can make changes to that file, but make sure to add new
20832083
keys instead of updating existing ones, otherwise Vim will skip
2084-
loading the file (thinking is hasn't been changed).
2084+
loading the file (thinking it hasn't been changed).
20852085

20862086
*v:completed_item* *completed_item-variable*
20872087
v:completed_item

runtime/doc/syntax.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*syntax.txt* For Vim version 9.1. Last change: 2025 Feb 20
1+
*syntax.txt* For Vim version 9.1. Last change: 2025 Feb 23
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -5432,6 +5432,10 @@ in their own color.
54325432
See |:highlight-default| for the optional [default]
54335433
argument.
54345434

5435+
:hi[ghlight][!] [default] link {from-group} {to-group}
5436+
:hi[ghlight][!] [default] link {from-group} NONE
5437+
See |:hi-link|.
5438+
54355439
Normally a highlight group is added once when starting up. This sets the
54365440
default values for the highlighting. After that, you can use additional
54375441
highlight commands to change the arguments that you want to set to non-default

runtime/doc/version9.txt

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.1. Last change: 2025 Feb 11
1+
*version9.txt* For Vim version 9.1. Last change: 2025 Feb 23
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -41573,8 +41573,11 @@ Include the "linematch" algorithm for the 'diffopt' setting. This aligns
4157341573
changes between buffers on similar lines improving the diff highlighting in
4157441574
Vim
4157541575

41576-
Adjusted default values ~
41577-
-----------------------
41576+
*changed-9.2*
41577+
Changed~
41578+
-------
41579+
41580+
Default values: ~
4157841581
- the default 'history' option value has been increased to 200 and removed
4157941582
from |defaults.vim|
4158041583
- the default 'backspace' option for Vim has been set to "indent,eol,start"
@@ -41584,61 +41587,69 @@ Adjusted default values ~
4158441587
- the default value of the 'keyprotocol' option has been updated and support
4158541588
for the ghostty terminal emulator (using kitty protocol) has been added
4158641589

41587-
*changed-9.2*
41588-
Changed~
41589-
-------
41590-
- use 'smoothscroll' logic for CTRL-F and CTRL-B for pagewise scrolling
41591-
- use 'smoothscroll' logic for CTRL-D and CTRL-U for half-pagewise scrolling
41590+
41591+
Completion: ~
41592+
- allow to complete directories from 'cdpath' for |:cd| and similar commands,
41593+
add the "cd_in_path" completion type for e.g. |:command-complete| and
41594+
|getcompletion()|
41595+
- allow to complete shell commands and files using the new shellcmdline
41596+
completion type using |:command-complete| and |getcmdcomplpat()|
41597+
- allow to specify additional attributes in the completion menu (allows to
41598+
mark deprecated attributes from LSP server) |complete-items|
41599+
- the completed word and completion type are provided when handling the
41600+
|CompleteDone| autocommand in the |v:event| dictionary
41601+
- |complete_info()| returns the list of matches shown in the poppu menu via
41602+
the "matches" key
41603+
- New option value for 'completeopt':
41604+
"nosort" - do not sort completion results
41605+
"preinsert" - highlight to be inserted values
41606+
- handle multi-line completion as expected
41607+
- improved commandline completion for the |:hi| command
41608+
41609+
Options: ~
4159241610
- the default for 'commentstring' contains whitespace padding to have
4159341611
automatic comments look nicer |comment-install|
4159441612
- 'completeopt' is now a |global-local| option.
4159541613
- 'nrformats' accepts the new "blank" suboption, to determine a signed or
4159641614
unsigned number based on whitespace in front of a minus sign.
41615+
- add 'cpoptions' flag "z" |cpo-z|, to disable some (traditional) vi
41616+
behaviour/inconsistency (see |d-special| and |cw|).
41617+
- 'rulerformat' now supports the |stl-%!| item
41618+
- use 'smoothscroll' logic for CTRL-F / CTRL-B for pagewise scrolling
41619+
and CTRL-D / CTRL-U for half-pagewise scrolling
41620+
41621+
Ex commands: ~
4159741622
- allow to specify a priority when defining a new sign |:sign-define|
41598-
- provide information about function arguments using the get(func, "arity")
41599-
function |get()-func|
4160041623
- |:bwipe| also wipes jumplist and tagstack data
4160141624
- moving in the buffer list using |:bnext| and similar commands, behaves as
4160241625
documented and skips help buffers (if not run from a help buffer, else
4160341626
moves to the next/previous help buffer).
41604-
- allow to complete directories from 'cdpath' for |:cd| and similar commands,
41605-
add the "cd_in_path" completion type for e.g. |:command-complete| and
41606-
|getcompletion()|
41607-
- allow to complete shell commands and files using the new shellcmdline
41608-
completion type using |:command-complete| and |getcmdcomplpat()|
41609-
- add 'cpoptions' flag "z" |cpo-z|, to disable some (traditional) vi
41610-
behaviour/inconsistency (see |d-special| and |cw|).
41611-
- allow to specify additional attributes in the completion menu (allows to
41612-
mark deprecated attributes from LSP server) |complete-items|
41613-
- the regex engines match correctly case-insensitive multi-byte characters
41614-
(and apply proper case folding)
4161541627
- |:keeppatterns| preserves the last substitute pattern when used with |:s|
41628+
41629+
Functions: ~
41630+
- provide information about function arguments using the get(func, "arity")
41631+
function |get()-func|
4161641632
- |setqflist()| and |setloclist()| can optionally try to preserve the current
4161741633
selection in the quickfix list with the "u" action.
41634+
- allow to pass local Vim script variables to python interpreter |py3eval()|
41635+
- |getwininfo()| now also returns the "leftcol" property for a window
41636+
- |v:stacktrace| The stack trace of the exception most recently caught and
41637+
not finished
41638+
- Add the optional {opts} |Dict| argument to |getchar()| to control: cursor
41639+
behaviour, return type and whether or not to simplify the returned key
41640+
41641+
Others: ~
41642+
- the regex engines match correctly case-insensitive multi-byte characters
41643+
(and apply proper case folding)
4161841644
- the putty terminal is detected using an |TermResponse| autocommand in
4161941645
|defaults.vim| and Vim switches to a dark background
4162041646
- the |help-TOC| package is included to ease navigating the documentation.
4162141647
- an interactive tutor plugin has been included |vim-tutor-mode|, can be
4162241648
started via |:Tutor|
4162341649
- improve the |vimtutor| and add a second chapter for more advanced tips
41624-
- allow to pass local Vim script variables to python interpreter |py3eval()|
41625-
- |getwininfo()| now also returns the "leftcol" property for a window
41626-
- 'rulerformat' now supports the |stl-%!| item
41627-
- the completed word and completion type are provided when handling the
41628-
|CompleteDone| autocommand in the |v:event| dictionary
41629-
- |complete_info()| returns the list of matches shown in the poppu menu via
41630-
the "matches" key
41631-
- |v:stacktrace| The stack trace of the exception most recently caught and
41632-
not finished
41633-
- New option value for 'completeopt':
41634-
"nosort" - do not sort completion results
41635-
"preinsert" - highlight to be inserted values
4163641650
- add |dist#vim9#Launch()| and |dist#vim9#Open()| to the |vim-script-library|
4163741651
and decouple it from |netrw|
4163841652
- new digraph "APPROACHES THE LIMIT" using ".="
41639-
- Add the optional {opts} |Dict| argument to |getchar()| to control: cursor
41640-
behaviour, return type and whether or not to simplify the returned key
41641-
- handle multi-line completion as expected
4164241653

4164341654
*added-9.2*
4164441655
Added ~

src/cmdexpand.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,6 +3221,8 @@ ExpandFromContext(
32213221
ret = ExpandMappings(pat, &regmatch, numMatches, matches);
32223222
else if (xp->xp_context == EXPAND_ARGOPT)
32233223
ret = expand_argopt(pat, xp, &regmatch, matches, numMatches);
3224+
else if (xp->xp_context == EXPAND_HIGHLIGHT_GROUP)
3225+
ret = expand_highlight_group(pat, xp, &regmatch, matches, numMatches);
32243226
#if defined(FEAT_TERMINAL)
32253227
else if (xp->xp_context == EXPAND_TERMINALOPT)
32263228
ret = expand_terminal_opt(pat, xp, &regmatch, matches, numMatches);
@@ -3239,6 +3241,21 @@ ExpandFromContext(
32393241
return ret;
32403242
}
32413243

3244+
int
3245+
ExpandGeneric(
3246+
char_u *pat,
3247+
expand_T *xp,
3248+
regmatch_T *regmatch,
3249+
char_u ***matches,
3250+
int *numMatches,
3251+
char_u *((*func)(expand_T *, int)),
3252+
// returns a string from the list
3253+
int escaped)
3254+
{
3255+
return ExpandGenericExt(
3256+
pat, xp, regmatch, matches, numMatches, func, escaped, 0);
3257+
}
3258+
32423259
/*
32433260
* Expand a list of names.
32443261
*
@@ -3249,18 +3266,23 @@ ExpandFromContext(
32493266
* If 'fuzzy' is TRUE, then fuzzy matching is used. Otherwise, regex matching
32503267
* is used.
32513268
*
3269+
* 'sortStartIdx' allows the caller to control sorting behavior. Items before
3270+
* the index will not be sorted. Pass 0 to sort all, and -1 to prevent any
3271+
* sorting.
3272+
*
32523273
* Returns OK when no problems encountered, FAIL for error (out of memory).
32533274
*/
32543275
int
3255-
ExpandGeneric(
3276+
ExpandGenericExt(
32563277
char_u *pat,
32573278
expand_T *xp,
32583279
regmatch_T *regmatch,
32593280
char_u ***matches,
32603281
int *numMatches,
32613282
char_u *((*func)(expand_T *, int)),
32623283
// returns a string from the list
3263-
int escaped)
3284+
int escaped,
3285+
int sortStartIdx)
32643286
{
32653287
int i;
32663288
garray_T ga;
@@ -3271,6 +3293,7 @@ ExpandGeneric(
32713293
int match;
32723294
int sort_matches = FALSE;
32733295
int funcsort = FALSE;
3296+
int sortStartMatchIdx = -1;
32743297

32753298
fuzzy = cmdline_fuzzy_complete(pat);
32763299
*matches = NULL;
@@ -3346,6 +3369,12 @@ ExpandGeneric(
33463369
}
33473370
#endif
33483371

3372+
if (sortStartIdx >= 0 && i >= sortStartIdx && sortStartMatchIdx == -1)
3373+
{
3374+
// Found first item to start sorting from. This is usually 0.
3375+
sortStartMatchIdx = ga.ga_len;
3376+
}
3377+
33493378
++ga.ga_len;
33503379
}
33513380

@@ -3371,14 +3400,14 @@ ExpandGeneric(
33713400
funcsort = TRUE;
33723401

33733402
// Sort the matches.
3374-
if (sort_matches)
3403+
if (sort_matches && sortStartMatchIdx != -1)
33753404
{
33763405
if (funcsort)
33773406
// <SNR> functions should be sorted to the end.
33783407
qsort((void *)ga.ga_data, (size_t)ga.ga_len, sizeof(char_u *),
33793408
sort_func_compare);
33803409
else
3381-
sort_strings((char_u **)ga.ga_data, ga.ga_len);
3410+
sort_strings((char_u **)ga.ga_data + sortStartMatchIdx, ga.ga_len - sortStartMatchIdx);
33823411
}
33833412

33843413
if (!fuzzy)

0 commit comments

Comments
 (0)