{
    "mode": "man",
    "parameter": "zshcompwid",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/zshcompwid/1/json",
    "generated": "2026-09-02T20:11:11Z",
    "sections": {
        "NAME": {
            "content": "zshcompwid - zsh completion widgets\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The  shell's  programmable  completion  mechanism  can  be  manipulated in two ways; here the\nlow-level features supporting the newer, function-based mechanism are  defined.   A  complete\nset  of shell functions based on these features is described in zshcompsys(1), and users with\nno interest in adding to that system (or, potentially, writing their own  --  see  dictionary\nentry  for  `hubris') should skip the current section.  The older system based on the compctl\nbuiltin command is described in zshcompctl(1).\n\nCompletion widgets are defined by the -C option to the zle builtin command  provided  by  the\nzsh/zle module (see zshzle(1)). For example,\n\nzle -C complete expand-or-complete completer\n\ndefines  a  widget  named  `complete'.  The second argument is the name of any of the builtin\nwidgets that handle completions: complete-word,  expand-or-complete,  expand-or-complete-pre‐\nfix,   menu-complete,   menu-expand-or-complete,   reverse-menu-complete,   list-choices,  or\ndelete-char-or-list.  Note that this will still work even if the widget in question has  been\nre-bound.\n\nWhen this newly defined widget is bound to a key using the bindkey builtin command defined in\nthe zsh/zle module (see zshzle(1)), typing that key will call the shell function `completer'.\nThis  function  is responsible for generating completion matches using the builtins described\nbelow.  As with other ZLE widgets, the function is called with its standard input closed.\n\nOnce the function returns, the completion code  takes  over  control  again  and  treats  the\nmatches in the same manner as the specified builtin widget, in this case expand-or-complete.\n",
            "subsections": []
        },
        "COMPLETION SPECIAL PARAMETERS": {
            "content": "The  parameters ZLEREMOVESUFFIXCHARS and ZLESPACESUFFIXCHARS are used by the completion\nmechanism, but are not special. See Parameters Used By The Shell in zshparam(1).\n\nInside completion widgets, and any functions called from them, some parameters  have  special\nmeaning; outside these functions they are not special to the shell in any way.  These parame‐\nters are used to pass information between the completion code and the completion widget. Some\nof the builtin commands and the condition codes use or change the current values of these pa‐\nrameters.   Any existing values will be hidden during execution of completion widgets; except\nfor compstate, the parameters are reset on each  function  exit  (including  nested  function\ncalls  from  within  the  completion widget) to the values they had when the function was en‐\ntered.\n\nCURRENT\nThis is the number of the current word, i.e. the word the cursor is  currently  on  in\nthe  words array.  Note that this value is only correct if the ksharrays option is not\nset.\n\nIPREFIX\nInitially this will be set to the empty string.  This parameter functions like PREFIX;\nit contains a string which precedes the one in PREFIX and is not  considered  part  of\nthe  list of matches.  Typically, a string is transferred from the beginning of PREFIX\nto the end of IPREFIX, for example:\n\nIPREFIX=${PREFIX%%\\=*}=\nPREFIX=${PREFIX#*=}\n\ncauses the part of the prefix up to and including the  first  equal  sign  not  to  be\ntreated  as  part  of a matched string.  This can be done automatically by the compset\nbuiltin, see below.\n\nISUFFIX\nAs IPREFIX, but for a suffix that should not be considered part of the  matches;  note\nthat the ISUFFIX string follows the SUFFIX string.\n\nPREFIX Initially  this  will be set to the part of the current word from the beginning of the\nword up to the position of the cursor; it may be altered to give a common  prefix  for\nall matches.\n\nQIPREFIX\nThis  parameter  is read-only and contains the quoted string up to the word being com‐\npleted. E.g. when completing `\"foo', this parameter contains the double quote. If  the\n-q  option of compset is used (see below), and the original string was `\"foo bar' with\nthe cursor on the `bar', this parameter contains `\"foo '.\n\nQISUFFIX\nLike QIPREFIX, but containing the suffix.\n\nSUFFIX Initially this will be set to the part of the current word from the cursor position to\nthe end; it may be altered to give a common suffix for all matches.  It is most useful\nwhen the option COMPLETEINWORD is set, as otherwise the whole word  on  the  command\nline is treated as a prefix.\n",
            "subsections": [
                {
                    "name": "compstate",
                    "content": "This  is  an  associative  array with various keys and values that the completion code\nuses to exchange information with the completion widget.  The keys are:\n\nallquotes\nThe -q option of the compset builtin command (see below) allows a quoted string\nto be broken into separate words; if the cursor is on one of those words,  that\nword  will be completed, possibly invoking `compset -q' recursively.  With this\nkey it is possible to test the types of quoted strings which are currently bro‐\nken into parts in this fashion.  Its value  contains  one  character  for  each\nquoting level.  The characters are a single quote or a double quote for strings\nquoted with these characters, a dollars sign for strings quoted with $'...' and\na backslash for strings not starting with a quote character.  The first charac‐\nter in the value always corresponds to the innermost quoting level.\n\ncontext\nThis will be set by the completion code to the overall context in which comple‐\ntion is attempted. Possible values are:\n\narrayvalue\nwhen  completing  inside  the value of an array parameter assignment; in\nthis case the words array contains the words inside the parentheses.\n\nbraceparameter\nwhen completing the name of a parameter in a parameter expansion  begin‐\nning  with  ${.  This context will also be set when completing parameter\nflags following ${(; the full command line argument is presented and the\nhandler must test the value to be completed to ascertain  that  this  is\nthe case.\n\nassignparameter\nwhen completing the name of a parameter in a parameter assignment.\n\ncommand\nwhen  completing for a normal command (either in command position or for\nan argument of the command).\n\ncondition\nwhen completing inside a `[[...]]' conditional expression; in this  case\nthe  words  array contains only the words inside the conditional expres‐\nsion.\n\nmath   when completing in a mathematical environment such as a  `((...))'  con‐\nstruct.\n\nparameter\nwhen  completing the name of a parameter in a parameter expansion begin‐\nning with $ but not ${.\n\nredirect\nwhen completing after a redirection operator.\n\nsubscript\nwhen completing inside a parameter subscript.\n\nvalue  when completing the value of a parameter assignment.\n\nexact  Controls the behaviour when the RECEXACT option is set.  It will be set to ac‐\ncept if an exact match would be accepted, and will be unset otherwise.\n\nIf it was set when at least one match equal to the string on the line was  gen‐\nerated, the match is accepted.\n\nexactstring\nThe string of an exact match if one was found, otherwise unset.\n\nignored\nThe  number  of  completions  that were ignored because they matched one of the\npatterns given with the -F option to the compadd builtin command.\n\ninsert This controls the manner in which a match is inserted into  the  command  line.\nOn  entry  to the widget function, if it is unset the command line is not to be\nchanged; if set to unambiguous, any prefix common to all matches is to  be  in‐\nserted; if set to automenu-unambiguous, the common prefix is to be inserted and\nthe  next  invocation  of the completion code may start menu completion (due to\nthe AUTOMENU option being set); if set to menu  or  automenu  menu  completion\nwill  be  started  for the matches currently generated (in the latter case this\nwill happen because the AUTOMENU is set).  The  value  may  also  contain  the\nstring  `tab' when the completion code would normally not really do completion,\nbut only insert the TAB character.\n\nOn exit it may be set to any of the values above (where setting it to the empty\nstring is the same as unsetting it), or to a number, in which  case  the  match\nwhose number is given will be inserted into the command line.  Negative numbers\ncount  backward  from  the  last match (with `-1' selecting the last match) and\nout-of-range values are wrapped around, so that a value  of  zero  selects  the\nlast  match and a value one more than the maximum selects the first. Unless the\nvalue of this key ends in a space, the match is inserted as in a  menu  comple‐\ntion, i.e. without automatically appending a space.\n\nBoth  menu  and  automenu  may  also specify the number of the match to insert,\ngiven after a colon.  For example, `menu:2' says to start menu completion,  be‐\nginning with the second match.\n\nNote that a value containing the substring `tab' makes the matches generated be\nignored and only the TAB be inserted.\n\nFinally,  it  may  also be set to all, which makes all matches generated be in‐\nserted into the line.\n\ninsertpositions\nWhen the completion system inserts an unambiguous string into the  line,  there\nmay  be multiple places where characters are missing or where the character in‐\nserted differs from at least one match.  The value of this key contains a colon\nseparated list of all these positions, as indexes into the command line.\n\nlastprompt\nIf this is set to a non-empty string for every match added, the completion code\nwill move the cursor back to the previous prompt after the list of  completions\nhas  been  displayed.   Initially  this  is  set  or unset according to the AL‐\nWAYSLASTPROMPT option.\n\nlist   This controls whether or how the list of matches will be displayed.  If  it  is\nunset  or  empty they will never be listed; if its value begins with list, they\nwill always be listed; if it begins with autolist or ambiguous,  they  will  be\nlisted when the AUTOLIST or LISTAMBIGUOUS options respectively would normally\ncause them to be.\n\nIf  the substring force appears in the value, this makes the list be shown even\nif there is only one match. Normally, the list would be shown only if there are\nat least two matches.\n\nThe value contains the substring packed if the LISTPACKED option  is  set.  If\nthis  substring is given for all matches added to a group, this group will show\nthe LISTPACKED behavior. The same is done for the LISTROWSFIRST option  with\nthe substring rows.\n\nFinally,  if  the  value contains the string explanations, only the explanation\nstrings, if any, will be listed and if it contains messages, only the  messages\n(added  with the -x option of compadd) will be listed.  If it contains both ex‐\nplanations and messages both kinds of explanation strings will be  listed.   It\nwill  be  set  appropriately on entry to a completion widget and may be changed\nthere.\n\nlistlines\nThis gives the number of lines that are needed to display the full list of com‐\npletions.  Note that to calculate the total number of lines to display you need\nto add the number of lines needed for the command line to this value,  this  is\navailable as the value of the BUFFERLINES special parameter.\n\nlistmax\nInitially  this is set to the value of the LISTMAX parameter.  It may be set to\nany other value; when the widget exits this value will be used in the same  way\nas the value of LISTMAX.\n\nnmatches\nThe number of matches added by the completion code so far.\n\noldinsert\nOn  entry  to  the widget this will be set to the number of the match of an old\nlist of completions that is currently inserted into the  command  line.  If  no\nmatch has been inserted, this is unset.\n\nAs  with  oldlist, the value of this key will only be used if it is the string\nkeep. If it was set to this value by the widget and there was an old match  in‐\nserted  into  the command line, this match will be kept and if the value of the\ninsert key specifies that another match should be inserted, this  will  be  in‐\nserted after the old one.\n\noldlist\nThis  is set to yes if there is still a valid list of completions from a previ‐\nous completion at the time the widget is invoked.  This  will  usually  be  the\ncase  if  and only if the previous editing operation was a completion widget or\none of the builtin completion functions.  If there is a valid list  and  it  is\nalso currently shown on the screen, the value of this key is shown.\n\nAfter the widget has exited the value of this key is only used if it was set to\nkeep.  In this case the completion code will continue to use this old list.  If\nthe widget generated new matches, they will not be used.\n\nparameter\nThe  name  of the parameter when completing in a subscript or in the value of a\nparameter assignment.\n\npatterninsert\nNormally this is set to menu, which specifies that menu completion will be used\nwhenever a set of matches was generated using patternmatch (see below).  If it\nis set to any other non-empty string by the user and menu completion is not se‐\nlected by other option settings, the code will instead insert any common prefix\nfor the generated matches as with normal completion.\n\npatternmatch\nLocally controls the behaviour given by the GLOBCOMPLETE option.  Initially it\nis set to `*' if and only if the option is set.  The completion widget may  set\nit  to  this  value, to an empty string (which has the same effect as unsetting\nit), or to any other non-empty string.  If it is non-empty, unquoted  metachar‐\nacters  on the command line will be treated as patterns; if it is `*', then ad‐\nditionally a wildcard `*' is assumed at the cursor position; if it is empty  or\nunset, metacharacters will be treated literally.\n\nNote that the match specifications given to the compadd builtin command are not\nused if this is set to a non-empty string.\n\nquote  When  completing inside quotes, this contains the quotation character (i.e. ei‐\nther a single quote, a double quote, or a backtick).  Otherwise it is unset.\n\nquoting\nWhen completing inside single quotes, this is set to the string single;  inside\ndouble  quotes, the string double; inside backticks, the string backtick.  Oth‐\nerwise it is unset.\n\nredirect\nThe redirection operator when completing in a redirection position, i.e. one of\n<, >, etc.\n\nrestore\nThis is set to auto before a function is entered, which forces the special  pa‐\nrameters mentioned above (words, CURRENT, PREFIX, IPREFIX, SUFFIX, and ISUFFIX)\nto  be  restored to their previous values when the function exits.   If a func‐\ntion unsets it or sets it to any other string, they will not be restored.\n\ntoend Specifies the occasions on which the cursor is moved to the  end  of  a  string\nwhen  a  match is inserted.  On entry to a widget function, it may be single if\nthis will happen when a single unambiguous match was inserted or  match  if  it\nwill happen any time a match is inserted (for example, by menu completion; this\nis likely to be the effect of the ALWAYSTOEND option).\n\nOn exit, it may be set to single as above.  It may also be set to always, or to\nthe  empty  string or unset; in those cases the cursor will be moved to the end\nof the string always or never respectively.  Any other  string  is  treated  as\nmatch.\n\nunambiguous\nThis key is read-only and will always be set to the common (unambiguous) prefix\nthe completion code has generated for all matches added so far.\n\nunambiguouscursor\nThis  gives  the position the cursor would be placed at if the common prefix in\nthe unambiguous key were inserted, relative to the value of that key. The  cur‐\nsor would be placed before the character whose index is given by this key.\n\nunambiguouspositions\nThis  contains  all  positions  where  characters in the unambiguous string are\nmissing or where the character inserted  differs  from  at  least  one  of  the\nmatches.  The positions are given as indexes into the string given by the value\nof the unambiguous key.\n\nvared  If completion is called while editing a line using the vared builtin, the value\nof  this key is set to the name of the parameter given as an argument to vared.\nThis key is only set while a vared command is active.\n\nwords  This array contains the words present on the command line currently being edited.\n"
                }
            ]
        },
        "COMPLETION BUILTIN COMMANDS": {
            "content": "compadd [ -akqQfenUl12C ] [ -F array ]\n[-P prefix ] [ -S suffix ]\n[-p hidden-prefix ] [ -s hidden-suffix ]\n[-i ignored-prefix ] [ -I ignored-suffix ]\n[-W file-prefix ] [ -d array ]\n[-J group-name ] [ -X explanation ] [ -x message ]\n[-V group-name ] [ -o [ order ] ]\n[-r remove-chars ] [ -R remove-func ]\n[-D array ] [ -O array ] [ -A array ]\n[-E number ]\n[-M match-spec ] [ -- ] [ completions ... ]\n\nThis builtin command can be used to add matches directly and control all the  informa‐\ntion  the  completion  code stores with each possible completion. The return status is\nzero if at least one match was added and non-zero if no matches were added.\n\nThe completion code breaks each match into seven fields in the order:\n\n<ipre><apre><hpre><body><hsuf><asuf><isuf>\n\nThe first field is an ignored prefix taken from the command line, the contents of  the\nIPREFIX  parameter  plus the string given with the -i option. With the -U option, only\nthe string from the -i option is used. The field <apre> is an optional  prefix  string\ngiven with the -P option.  The <hpre> field is a string that is considered part of the\nmatch but that should not be shown when listing completions, given with the -p option;\nfor  example, functions that do filename generation might specify a common path prefix\nthis way.  <body> is the part of the match that should appear in the list  of  matches\nshown  to the user.  The suffixes <hsuf>, <asuf> and <isuf> correspond to the prefixes\n<hpre>, <apre> and <ipre> and are given by the options -s, -S and -I, respectively.\n\nThe supported flags are:\n\n-P prefix\nThis gives a string to be inserted before each match.  The string given is  not\nconsidered  as part of the match and any shell metacharacters in it will not be\nquoted when the string is inserted.\n\n-S suffix\nLike -P, but gives a string to be inserted after each match.\n\n-p hidden-prefix\nThis gives a string that should be inserted before each match but  that  should\nnot  appear  in the list of matches. Unless the -U option is given, this string\nmust be matched as part of the string on the command line.\n\n-s hidden-suffix\nLike `-p', but gives a string to insert after each match.\n\n-i ignored-prefix\nThis gives a string to insert just before any string given with  the  `-P'  op‐\ntion.  Without `-P' the string is inserted before the string given with `-p' or\ndirectly before each match.\n\n-I ignored-suffix\nLike -i, but gives an ignored suffix.\n\n-a     With this flag the completions are taken as names of arrays and the actual com‐\npletions are their values.  If only some elements of the arrays are needed, the\ncompletions may also contain subscripts, as in `foo[2,-1]'.\n\n-k     With this flag the completions are taken as names of associative arrays and the\nactual  completions are their keys.  As for -a, the words may also contain sub‐\nscripts, as in `foo[(R)*bar*]'.\n\n-d array\nThis adds per-completion display strings. The array should contain one  element\nper  completion  given. The completion code will then display the first element\ninstead of the first completion, and so on. The array may be given as the  name\nof  an array parameter or directly as a space-separated list of words in paren‐\ntheses.\n\nIf there are fewer display strings than completions, the  leftover  completions\nwill  be displayed unchanged and if there are more display strings than comple‐\ntions, the leftover display strings will be silently ignored.\n\n-l     This option only has an effect if used together with the -d option.  If  it  is\ngiven, the display strings are listed one per line, not arrayed in columns.\n\n-o [ order ]\nThis controls the order in which matches are sorted. order is a comma-separated\nlist comprising the following possible values.  These values can be abbreviated\nto  their  initial  two or three characters.  Note that the order forms part of\nthe group name space so matches with different orderings will  not  be  in  the\nsame group.\n\nmatch  If  given,  the  order of the output is determined by the match strings;\notherwise it is determined by the  display  strings  (i.e.  the  strings\ngiven  by  the  -d option). This is the default if `-o' is specified but\nthe order argument is omitted.\n\nnosort This specifies that the  completions  are  pre-sorted  and  their  order\nshould  be  preserved.   This value only makes sense alone and cannot be\ncombined with any others.\n\nnumeric\nIf the matches include numbers, sort them numerically rather than  lexi‐\ncographically.\n\nreverse\nArrange the matches backwards by reversing the sort ordering.\n\n-J group-name\nGives the name of the group that the matches should be stored in.\n\n-V group-name\nLike  -J but naming an unsorted group. This option is identical to the combina‐\ntion of -J and -o nosort.\n\n-1     If given together with the -V option, makes only consecutive duplicates in  the\ngroup  be  removed. If combined with the -J option, this has no visible effect.\nNote that groups with and without this flag are in different name spaces.\n\n-2     If given together with the -J or -V  option,  makes  all  duplicates  be  kept.\nAgain, groups with and without this flag are in different name spaces.\n\n-X explanation\nThe  explanation  string  will  be  printed with the list of matches, above the\ngroup currently selected.\n\nWithin the explanation, the following sequences may be used to  specify  output\nattributes  as  described  in the section EXPANSION OF PROMPT SEQUENCES in zsh‐\nmisc(1): `%B', `%S', `%U', `%F', `%K' and their  lower  case  counterparts,  as\nwell as `%{...%}'.  `%F', `%K' and `%{...%}' take arguments in the same form as\nprompt  expansion.   (Note that the sequence `%G' is not available; an argument\nto `%{' should be used instead.)  The sequence `%%' produces a literal `%'.\n\nThese sequences are most often employed by users when  customising  the  format\nstyle  (see zshcompsys(1)), but they must also be taken into account when writ‐\ning completion functions, as passing descriptions with unescaped `%' characters\nto utility functions such as arguments and message may produce unexpected re‐\nsults. If arbitrary text is to be passed in a description, it  can  be  escaped\nusing e.g. ${mystr//\\%/%%}.\n\n-x message\nLike  -X,  but  the message will be printed even if there are no matches in the\ngroup.\n\n-q     The suffix given with -S will be automatically removed if  the  next  character\ntyped is a blank or does not insert anything, or if the suffix consists of only\none character and the next character typed is the same character.\n\n-r remove-chars\nThis  is  a  more versatile form of the -q option.  The suffix given with -S or\nthe slash automatically added after completing directories  will  be  automati‐\ncally  removed  if the next character typed inserts one of the characters given\nin the remove-chars.  This string is parsed as a characters  class  and  under‐\nstands  the  backslash  sequences  used by the print command.  For example, `-r\n\"a-z\\t\"' removes the suffix if the next character typed inserts  a  lower  case\ncharacter  or  a  TAB, and `-r \"^0-9\"' removes the suffix if the next character\ntyped inserts anything but a digit. One extra backslash sequence is  understood\nin  this  string:  `\\-' stands for all characters that insert nothing. Thus `-S\n\"=\" -q' is the same as `-S \"=\" -r \"= \\t\\n\\-\"'.\n\nThis option may also be used without the  -S  option;  then  any  automatically\nadded space will be removed when one of the characters in the list is typed.\n\n-R remove-func\nThis  is  another  form  of the -r option. When a match has been accepted and a\nsuffix has been inserted, the function remove-func will  be  called  after  the\nnext character typed.  It is passed the length of the suffix as an argument and\ncan  use the special parameters available in ordinary (non-completion) zle wid‐\ngets (see zshzle(1)) to analyse and modify the command line.\n\n-f     If this flag is given, all of the matches built from the completions are marked\nas being the names of files.  They are not required to be actual filenames, but\nif they are, and the option LISTTYPES is set, the  characters  describing  the\ntypes  of  the  files in the completion lists will be shown. This also forces a\nslash to be added when the name of a directory is completed.\n\n-e     This flag can be used to tell the completion code that the  matches  added  are\nparameter  names for a parameter expansion. This will make the AUTOPARAMSLASH\nand AUTOPARAMKEYS options be used for the matches.\n\n-W file-prefix\nThis string is a pathname that will be prepended to each  match  together  with\nany  prefix specified by the -p option to form a complete filename for testing.\nHence it is only useful if combined with the -f flag, as  the  tests  will  not\notherwise be performed.\n\n-F array\nSpecifies  an  array  containing patterns.  completions that match one of these\npatterns are ignored, that is, not considered to be matches.\n\nThe array may be the name of an array parameter or a list of  literal  patterns\nenclosed in parentheses and quoted, as in `-F \"(*?.o *?.h)\"'. If the name of an\narray is given, the elements of the array are taken as the patterns.\n\n-Q     This  flag instructs the completion code not to quote any metacharacters in the\nmatches when inserting them into the command line.\n\n-M match-spec\nThis gives local match specifications as described below in the  section  `Com‐\npletion  Matching  Control'.  This option may be given more than once.  In this\ncase all match-specs given are concatenated with spaces between  them  to  form\nthe  specification  string  to use.  Note that they will only be used if the -U\noption is not given.\n\n-n     Specifies that matching completions are to be added to the set of matches,  but\nare not to be listed to the user.\n\n-U     If  this  flag is given, all completions are added to the set of matches and no\nmatching will be done by the completion code. Normally this is  used  in  func‐\ntions that do the matching themselves.\n\n-O array\nIf  this  option is given, the completions are not added to the set of matches.\nInstead, matching is done as usual and all of the completions that  match  will\nbe stored in the array parameter whose name is given as array.\n\n-A array\nAs  the  -O option, except that instead of those of the completions which match\nbeing stored in array, the strings generated internally by the completion  code\nare  stored.   For example, with a match specification of `-M \"L:|no=\"', a cur‐\nrent word of `nof' and completions of `foo', this option stores the string `no‐\nfoo' in the array, whereas the -O option stores the `foo' originally given.\n\n-D array\nAs with -O, the completions are not added to  the  set  of  matches.   Instead,\nwhenever the nth completion does not match, the nth element of the array is re‐\nmoved.   Elements  for which the corresponding completion matches are retained.\nThis option can be used more than once to remove elements from multiple arrays.\n\n-C     This option adds a special match which expands to all other  matches  when  in‐\nserted into the line, even those that are added after this option is used.  To‐\ngether  with  the  -d  option it is possible to specify a string that should be\ndisplayed in the list for this special match.  If no string is given,  it  will\nbe  shown  as  a  string  containing the strings that would be inserted for the\nother matches, truncated to the width of the screen.\n\n-E number\nThis option adds number empty matches  after  matching  completions  have  been\nadded.   An empty match takes up space in completion listings but will never be\ninserted in the line and can't be selected with menu completion or menu  selec‐\ntion.   This  makes empty matches only useful to format completion lists and to\nmake explanatory string be shown in completion lists (since empty  matches  can\nbe  given  display  strings with the -d option).  And because all but one empty\nstring would otherwise be removed, this option implies the -V  and  -2  options\n(even  if an explicit -J option is given).  This can be important to note as it\naffects the name space into which matches are added.\n\n-\n--     This flag ends the list of flags and options. All arguments after  it  will  be\ntaken as the completions even if they begin with hyphens.\n\nExcept  for  the -M flag, if any of these flags is given more than once, the first one\n(and its argument) will be used.\n\ncompset -p number\ncompset -P [ number ] pattern\ncompset -s number\ncompset -S [ number ] pattern\ncompset -n begin [ end ]\ncompset -N beg-pat [ end-pat ]",
            "subsections": [
                {
                    "name": "compset -q",
                    "content": "This command simplifies modification of the special parameters, while its return  sta‐\ntus allows tests on them to be carried out.\n\nThe options are:\n\n-p number\nIf  the  value  of the PREFIX parameter is at least number characters long, the\nfirst number characters are removed from it and appended to the contents of the\nIPREFIX parameter.\n\n-P [ number ] pattern\nIf the value of the PREFIX parameter begins with anything that matches the pat‐\ntern, the matched portion is removed from PREFIX and appended to IPREFIX.\n\nWithout the optional number, the longest match  is  taken,  but  if  number  is\ngiven,  anything up to the numberth match is moved.  If the number is negative,\nthe numberth longest match is moved. For example, if PREFIX contains the string\n`a=b=c', then compset -P '*\\=' will move the string `a=b=' into the IPREFIX pa‐\nrameter, but compset -P 1 '*\\=' will move only the string `a='.\n\n-s number\nAs -p, but transfer the last number characters from the value of SUFFIX to  the\nfront of the value of ISUFFIX.\n\n-S [ number ] pattern\nAs -P, but match the last portion of SUFFIX and transfer the matched portion to\nthe front of the value of ISUFFIX.\n\n-n begin [ end ]\nIf  the  current word position as specified by the parameter CURRENT is greater\nthan or equal to begin, anything up to the beginth word  is  removed  from  the\nwords array and the value of the parameter CURRENT is decremented by begin.\n\nIf the optional end is given, the modification is done only if the current word\nposition  is also less than or equal to end. In this case, the words from posi‐\ntion end onwards are also removed from the words array.\n\nBoth begin and end may be negative to count backwards from the last element  of\nthe words array.\n\n-N beg-pat [ end-pat ]\nIf  one of the elements of the words array before the one at the index given by\nthe value of the parameter CURRENT matches the pattern beg-pat, all elements up\nto and including the matching one are removed from  the  words  array  and  the\nvalue of CURRENT is changed to point to the same word in the changed array.\n\nIf  the  optional pattern end-pat is also given, and there is an element in the\nwords array matching this pattern, the parameters are modified only if the  in‐\ndex of this word is higher than the one given by the CURRENT parameter (so that\nthe matching word has to be after the cursor). In this case, the words starting\nwith  the  one matching end-pat are also removed from the words array. If words\ncontains no word matching end-pat, the testing and modification is performed as\nif it were not given.\n\n-q     The word currently being completed is split on spaces into separate words,  re‐\nspecting  the  usual shell quoting conventions.  The resulting words are stored\nin the words array, and CURRENT, PREFIX, SUFFIX,  QIPREFIX,  and  QISUFFIX  are\nmodified to reflect the word part that is completed.\n\nIn all the above cases the return status is zero if the test succeeded and the parame‐\nters  were  modified  and  non-zero  otherwise. This allows one to use this builtin in\ntests such as:\n\nif compset -P '*\\='; then ...\n\nThis forces anything up to and including the last equal sign to be ignored by the com‐\npletion code.\n\ncompcall [ -TD ]\nThis allows the use of completions defined with the compctl builtin from  within  com‐\npletion  widgets.   The  list of matches will be generated as if one of the non-widget\ncompletion functions (complete-word, etc.)  had been called, except that only compctls\ngiven for specific commands are used. To force the code  to  try  completions  defined\nwith  the  -T option of compctl and/or the default completion (whether defined by com‐\npctl -D or the builtin default) in the appropriate places, the -T and/or -D flags  can\nbe passed to compcall.\n\nThe  return  status can be used to test if a matching compctl definition was found. It\nis non-zero if a compctl was found and zero otherwise.\n\nNote that this builtin is defined by the zsh/compctl module.\n"
                }
            ]
        },
        "COMPLETION CONDITION CODES": {
            "content": "The following additional condition codes for use within the [[ ... ]] construct are available\nin completion widgets.  These work on the special parameters.  All of these tests can also be\nperformed by the compset builtin, but in the case of the condition codes the contents of  the\nspecial parameters are not modified.\n",
            "subsections": [
                {
                    "name": "-prefix",
                    "content": "true if the test for the -P option of compset would succeed.\n"
                },
                {
                    "name": "-suffix",
                    "content": "true if the test for the -S option of compset would succeed.\n"
                },
                {
                    "name": "-after _",
                    "content": "true if the test of the -N option with only the beg-pat given would succeed.\n"
                },
                {
                    "name": "-between _",
                    "content": "true if the test for the -N option with both patterns would succeed.\n"
                }
            ]
        },
        "COMPLETION MATCHING CONTROL": {
            "content": "When the user invokes completion, the current word on the command line (that is, the word the\ncursor  is  currently  on)  is used to generate a match pattern.  Only those completions that\nmatch the pattern are offered to the user as matches.\n\nThe default match pattern is generated from the current word by either\n\n•      appending a `*' (matching any number of characters in a completion) or,\n\n•      if the shell option COMPLETEINWORD is set, inserting a `*' at the cursor position.\n\nThis narrow pattern can be broadened selectively by passing a match specification to the com‐\npadd builtin command through its -M option (see  `Completion  Builtin  Commands'  above).   A\nmatch  specification consists of one or more matchers separated by whitespace.  Matchers in a\nmatch specification are applied one at a time, from left to right.  Once  all  matchers  have\nbeen  applied,  completions are compared to the final match pattern and non-matching ones are\ndiscarded.\n\n•      Note that the -M option is ignored if the current word contains a glob pattern and the\nshell option GLOBCOMPLETE is set or if the patternmatch key of the special  associa‐\ntive  array compstate is set to a non-empty value (see `Completion Special Parameters'\nabove).\n\n•      Users of the completion system (see zshcompsys(1))  should generally not  use  the  -M\noption  directly,  but rather use the matcher-list and matcher styles (see the subsec‐\ntion Standard Styles in the documentation for COMPLETION SYSTEM CONFIGURATION in  zsh‐\ncompsys(1)).\n\nEach matcher consists of\n\n•      a case-sensitive letter\n\n•      a `:',\n\n•      one or more patterns separated by pipes (`|'),\n\n•      an equals sign (`='), and\n\n•      another pattern.\n\nThe  patterns  before  the  `='  are  used to match substrings of the current word.  For each\nmatched substring, the corresponding part of the match pattern is broadened with the  pattern\nafter the `=', by means of a logical OR.\n\nEach pattern in a matcher cosists of either\n\n•      the empty string or\n\n•      a sequence of\n\n•      literal characters (which may be quoted with a `\\'),\n\n•      question marks (`?'),\n\n•      bracket expressions (`[...]'; see the subsection Glob Operators in the documen‐\ntation for GLOB OPERATORS in zshexpn(1)), and/or\n\n•      brace expressions (see below).\n\n\nOther shell patterns are not allowed.\n\nA brace expression, like a bracket expression, consists of a list of\n\n•      literal characters,\n\n•      ranges (`0-9'), and/or\n\n•      character classes (`[:name:]').\n\nHowever, they differ from each other as follows:\n\n•      A brace expression is delimited by a pair of braces (`{...}').\n\n•      Brace  expressions  do  not  support negations.  That is, an initial `!' or `^' has no\nspecial meaning and will be interpreted as a literal character.\n\n•      When a character in the current word matches the nth pattern in  a  brace  expression,\nthe  corresponding part of the match pattern is broadened only with the nth pattern of\nthe brace expression on the other side of the `=', if there is one;  if  there  is  no\nbrace  expression  on the other side, then this pattern is the empty string.  However,\nif either brace expression has more elements than the other, then the  excess  entries\nare simply ignored.  When comparing indexes, each literal character or character class\ncounts  as one element, but each range is instead expanded to the full list of literal\ncharacters it represents.  Additionally, if on both sides of the `=', the nth  pattern\nis `[:upper:]' or `[:lower:]', then these are expanded as ranges, too.\n\nNote  that,  although  the  matching system does not yet handle multibyte characters, this is\nlikely to be a future extension.  Hence, using `[:upper:]'  and  `[:lower:]'  is  recommended\nover `A-Z' and `a-z'.\n\nBelow  are  the  different  forms of matchers supported.  Each uppercase form behaves exactly\nlike its lowercase counterpart, but adds an additional step after the match pattern has  fil‐\ntered  out non-matching completions:  Each of a match's substrings that was matched by a sub‐\npattern from an uppercase matcher is replaced with the corresponding substring of the current\nword.  However, patterns from lowercase matchers have higher weight:  If a substring  of  the\ncurrent word was matched by patterns from both a lowercase and an uppercase matcher, then the\nlowercase matcher's pattern wins and the corresponding part of the match is not modified.\n\nUnless  indicated  otherwise, each example listed assumes COMPLETEINWORD to be unset (as it\nis by default).\n\nm:word-pat=match-pat\nM:word-pat=match-pat\n\nFor each substring of the current word that matches word-pat, broaden the  correspond‐\ning part of the match pattern to additionally match match-pat.\n\nExamples:\n\nm:{[:lower:]}={[:upper:]}  lets any lower case character in the current word be\ncompleted to itself or its uppercase counterpart.  So, the  completions  `foo',\n`FOO' and `Foo' will are be considered matches for the word `fo'.\n\nM:=  inserts  every  underscore  from the current word into each match, in the\nsame relative position, determined by matching the substrings around  it.   So,\ngiven a completion `foo', the word `fo' will be completed to the match `foo',\neven though the latter was not present as a completion.\n\nb:word-pat=match-pat\nB:word-pat=match-pat\ne:word-pat=match-pat\nE:word-pat=match-pat\n\nFor  each  consecutive  substring  at  the b:eginning or e:nd of the current word that\nmatches word-pat, broaden the corresponding part of the match pattern to  additionally\nmatch match-pat.\n\nExamples:\n\n`b:-=+'  lets  any  number  of minuses at the start of the current word be com‐\npleted to a minus or a plus.\n\n`B:0=' adds all zeroes at the beginning of the current word to the beginning of\neach match.\n\nl:|word-pat=match-pat\nL:|word-pat=match-pat\nR:word-pat|=match-pat\nr:word-pat|=match-pat\n\nIf there is a substring at the l:eft or r:ight edge of the current word  that  matches\nword-pat,  then  broaden  the  corresponding part of the match pattern to additionally\nmatch match-pat.\n\nFor each l:, L:, r: and R: matcher (including the ones below), the  pattern  match-pat\nmay also be a `*'.  This matches any number of characters in a completion.\n\nExamples:\n\n`r:|=*'  appends  a `*' to the match pattern, even when COMPLETEINWORD is set\nand the cursor is not at the end of the current word.\n\nIf the current word starts with a minus, then `L:|-=' will prepend it  to  each\nmatch.\n\nl:anchor|word-pat=match-pat\nL:anchor|word-pat=match-pat\nr:word-pat|anchor=match-pat\nR:word-pat|anchor=match-pat\n\nFor  each  substring of the current word that matches word-pat and has on its l:eft or\nr:ight another substring matching anchor, broaden the corresponding part of the  match\npattern to additionally match match-pat.\n\nNote that these matchers (and the ones below) modify only what is matched by word-pat;\nthey  do  not  change the matching behavior of what is matched by anchor (or coanchor;\nsee the matchers below).  Thus, unless its corresponding part of the match pattern has\nbeen modified, the anchor in the current word has to match literally in  each  comple‐\ntion, just like any other substring of the current word.\n\nIf  a  matcher  includes at least one anchor (which includes the matchers with two an‐\nchors, below), then match-pat may also be `*' or `'.  `*' can match any  part  of  a\ncompletion  that  does  not contain any substrings matching anchor, whereas a `' can\nmatch any part of a completion, period.  (Note that this is different from the  behav‐\nior  of  `*'  in the anchorless forms of `l:' and `r:' and and also different from `*'\nand `' in glob expressions.)\n\nExamples:\n\n`r:|.=*' makes the completion `comp.sources.unix' a match for the word `..u' --\nbut not for the word `.u'.\n\nGiven a completion `--foo', the matcher  `L:--|no-='  will  complete  the  word\n`--no-' to the match `--no-foo'.\n\nl:anchor||coanchor=match-pat\nL:anchor||coanchor=match-pat\nr:coanchor||anchor=match-pat\nR:coanchor||anchor=match-pat\n\nFor any two consecutive substrings of the current word that match anchor and coanchor,\nin  the order given, insert the pattern match-pat between their corresponding parts in\nthe match pattern.\n\nNote that, unlike anchor, the pattern coanchor does not change what `*' can match.\n\nExamples:\n\n`r:?||[[:upper:]]=*' will complete the current word `fB' to  `fooBar',  but  it\nwill  not  complete  it  to `fooHooBar' (because `*' here cannot match anything\nthat includes a match for `[[:upper:]]), nor will it complete `B'  to  `fooBar'\n(because there is no character in the current word to match coanchor).\n\nGiven  the  current  word  `pass.n' and a completion `pass.byname', the matcher\n`L:.||[[:alpha:]]=by' will produce the match `pass.name'.\n\nx:\n\nIgnore this matcher and all matchers to its right.\n\nThis matcher is used to mark the end of a match specification.  In a single standalone\nlist of matchers, this has no use, but where match specifications are concatenated, as\nis often the case when using the completion system (see zshcompsys(1)), it  can  allow\none match specification to override another.\n",
            "subsections": []
        },
        "COMPLETION WIDGET EXAMPLE": {
            "content": "The first step is to define the widget:\n\nzle -C complete complete-word complete-files\n\nThen the widget can be bound to a key using the bindkey builtin command:\n\nbindkey '^X\\t' complete\n\nAfter  that the shell function complete-files will be invoked after typing control-X and TAB.\nThe function should then generate the matches, e.g.:\n\ncomplete-files () { compadd - * }\n\nThis function will complete files in the current directory matching the current word.\n\nzsh 5.9                                     May 14, 2022                               ZSHCOMPWID(1)",
            "subsections": []
        }
    },
    "summary": "zshcompwid - zsh completion widgets",
    "flags": [],
    "examples": [],
    "see_also": []
}