| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If the ZLE option is set (which it is by default in interactive shells) and the shell input is attached to the terminal, the user is able to edit command lines.
There are two display modes. The first, multiline mode, is the default. It only works if the TERM parameter is set to a valid terminal type that can move the cursor up. The second, single line mode, is used if TERM is invalid or incapable of moving the cursor up, or if the SINGLE_LINE_ZLE option is set. This mode is similar to ksh, and uses no termcap sequences. If TERM is "emacs", the ZLE option will be unset by default.
The parameters BAUD, COLUMNS, and LINES are also used by the line editor. Parameters Used By The Shell.
| 18.2 Keymaps | ||
| 18.3 Zle Builtins | ||
| 18.4 Widgets |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A keymap in ZLE contains a set of bindings between key sequences and ZLE commands. The empty key sequence cannot be bound.
There can be any number of keymaps at any time, and each keymap has one or more names. If all of a keymap's names are deleted, it disappears. bindkey can be used to manipulate keymap names.
Initially, there are four keymaps:
EMACS emulation
vi emulation - insert mode
vi emulation - command mode
fallback keymap
The `.safe' keymap is special. It can never be altered, and the name can never be removed. However, it can be linked to other names, which can be removed. In the future other special keymaps may be added; users should avoid using names beginning with `.' for their own keymaps.
In addition to these four names, either `emacs' or `viins' is also linked to the name `main'. If one of the VISUAL or EDITOR environment variables contain the string `vi' when the shell starts up then it will be `viins', otherwise it will be `emacs'. bindkey's -e and -v options provide a convenient way to override this default choice.
When the editor starts up, it will select the `main' keymap. If that keymap doesn't exist, it will use `.safe' instead.
In the `.safe' keymap, each single key is bound to self-insert, except for ^J (line feed) and ^M (return) which are bound to accept-line. This is deliberately not pleasant to use; if you are using it, it means you deleted the main keymap, and you should put it back.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When ZLE is reading a command from the terminal, it may read a sequence that is bound to some command and is also a prefix of a longer bound string. In this case ZLE will wait a certain time to see if more characters are typed, and if not (or they don't match any longer string) it will execute the binding. This timeout is defined by the KEYTIMEOUT parameter; its default is 0.4 sec. There is no timeout if the prefix string is not itself bound to a command.
The key timeout is also applied when ZLE is reading the bytes from a multibyte character string when it is in the appropriate mode. (This requires that the shell was compiled with multibyte mode enabled; typically also the locale has characters with the UTF-8 encoding, although any multibyte encoding known to the operating system is supported.) If the second or a subsequent byte is not read within the timeout period, the shell acts as if ? were typed and resets the input state.
As well as ZLE commands, key sequences can be bound to other strings, by using `bindkey -s'. When such a sequence is read, the replacement string is pushed back as input, and the command reading process starts again using these fake keystrokes. This input can itself invoke further replacement strings, but in order to detect loops the process will be stopped if there are twenty such replacements without a real command being read.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The ZLE module contains three related builtin commands. The bindkey command manipulates keymaps and key bindings; the vared command invokes ZLE on the value of a shell parameter; and the zle command manipulates editing widgets and allows command line access to ZLE commands from within shell functions.
bindkey's options can be divided into three categories: keymap selection, operation selection, and others. The keymap selection options are:
Selects keymap `emacs', and also links it to `main'.
Selects keymap `viins', and also links it to `main'.
Selects keymap `vicmd'.
The keymap specifies a keymap name.
If a keymap selection is required and none of the options above are used, the `main' keymap is used. Some operations do not permit a keymap to be selected, namely:
List all existing keymap names. If the -L option is also used, list in the form of bindkey commands to create the keymaps.
Delete all existing keymaps and reset to the default state.
Delete the named keymaps.
Make the new-keymap name an alias for old-keymap, so that both names refer to the same keymap. The names have equal standing; if either is deleted, the other remains. If there is already a keymap with the new-keymap name, it is deleted.
Create a new keymap, named new-keymap. If a keymap already has that name, it is deleted. If an old-keymap name is given, the new keymap is initialized to be a duplicate of it, otherwise the new keymap will be empty.
To use a newly created keymap, it should be linked to main. Hence the sequence of commands to create and use a new keymap `mymap' initialized from the emacs keymap (which remains unchanged) is:
bindkey -N mymap emacs bindkey -A mymap main |
Note that while `bindkey -A newmap main' will work when newmap is emacs or viins, it will not work for vicmd, as switching from vi insert to command mode becomes impossible.
The following operations act on the `main' keymap if no keymap selection option was given:
Add the built-in set of meta-key bindings to the selected keymap. Only keys that are unbound or bound to self-insert are affected.
Unbind the specified in-strings in the selected keymap. This is exactly equivalent to binding the strings to undefined-key.
When -R is also used, interpret the in-strings as ranges.
When -p is also used, the in-strings specify prefixes. Any binding that has the given in-string as a prefix, not including the binding for the in-string itself, if any, will be removed. For example,
bindkey -rpM viins '^[' |
will remove all bindings in the vi-insert keymap beginning with an escape character (probably cursor keys), but leave the binding for the escape character itself (probably vi-cmd-mode). This is incompatible with the option -R.
Bind each in-string to each out-string. When in-string is typed, out-string will be pushed back and treated as input to the line editor. When -R is also used, interpret the in-strings as ranges.
Bind each in-string to each command. When -R is used, interpret the in-strings as ranges.
List key bindings. If an in-string is specified, the binding of that string in the selected keymap is displayed. Otherwise, all key bindings in the selected keymap are displayed. (As a special case, if the -e or -v option is used alone, the keymap is not displayed - the implicit linking of keymaps is the only thing that happens.)
When the option -p is used, the in-string must be present. The listing shows all bindings which have the given key sequence as a prefix, not including any bindings for the key sequence itself.
When the -L option is used, the list is in the form of bindkey commands to create the key bindings.
When the -R option is used as noted above, a valid range consists of two characters, with an optional `-' between them. All characters between the two specified, inclusive, are bound as specified.
For either in-string or out-string, the following escape sequences are recognised:
bell character
backspace
escape
form feed
linefeed (newline)
carriage return
horizontal tab
vertical tab
character code in octal
character code in hexadecimal
character with meta bit set
control character
control character
In all other cases, `\' escapes the following character. Delete is written as `^?'. Note that `\M^?' and `^\M?' are not the same, and that (unlike emacs), the bindings `\M-X' and `\eX' are entirely distinct, although they are initialized to the same bindings by `bindkey -m'.
The value of the parameter name is loaded into the edit buffer, and the line editor is invoked. When the editor exits, name is set to the string value returned by the editor. When the -c flag is given, the parameter is created if it doesn't already exist. The -a flag may be given with -c to create an array parameter, or the -A flag to create an associative array. If the type of an existing parameter does not match the type to be created, the parameter is unset and recreated.
If an array or array slice is being edited, separator characters as defined in $IFS will be shown quoted with a backslash, as will backslashes themselves. Conversely, when the edited text is split into an array, a backslash quotes an immediately following separator character or backslash; no other special handling of backslashes, or any handling of quotes, is performed.
Individual elements of existing array or associative array parameters may be edited by using subscript syntax on name. New elements are created automatically, even without -c.
If the -p flag is given, the following string will be taken as the prompt to display at the left. If the -r flag is given, the following string gives the prompt to display at the right. If the -h flag is specified, the history can be accessed from ZLE. If the -e flag is given, typing ^D (Control-D) on an empty line causes vared to exit immediately with a non-zero return value.
The -M option gives a keymap to link to the main keymap during editing, and the -m option gives a keymap to link to the vicmd keymap during editing. For vi-style editing, this allows a pair of keymaps to override viins and vicmd. For emacs-style editing, only -M is normally needed but the -m option may still be used. On exit, the previous keymaps will be restored.
The zle builtin performs a number of different actions concerning ZLE.
With no options and no arguments, only the return status will be set. It is zero if ZLE is currently active and widgets could be invoked using this builtin command and non-zero otherwise. Note that even if non-zero status is returned, zle may still be active as part of the completion system; this does not allow direct calls to ZLE widgets.
Otherwise, which operation it performs depends on its options:
List all existing user-defined widgets. If the -L option is used, list in the form of zle commands to create the widgets.
When combined with the -a option, all widget names are listed, including the builtin ones. In this case the -L option is ignored.
If at least one string is given, nothing will be printed but the return status will be zero if all strings are names of existing widgets (or of user-defined widgets if the -a flag is not given) and non-zero if at least one string is not a name of an defined widget.
Delete the named widgets.
Make the new-widget name an alias for old-widget, so that both names refer to the same widget. The names have equal standing; if either is deleted, the other remains. If there is already a widget with the new-widget name, it is deleted.
Create a user-defined widget. If there is already a widget with the specified name, it is overwritten. When the new widget is invoked from within the editor, the specified shell function is called. If no function name is specified, it defaults to the same name as the widget. For further information, see the section Widgets in Zsh Line Editor.
Create a user-defined completion widget named widget. The completion widget will behave like the built-in completion-widget whose name is given as completion-widget. To generate the completions, the shell function function will be called. For further information, see Completion Widgets.
Redisplay the command line; this is to be called from within a user-defined widget to allow changes to become visible. If a display-string is given and not empty, this is shown in the status line (immediately below the line being edited).
If the optional strings are given they are listed below the prompt in the same way as completion lists are printed. If no strings are given but the -c option is used such a list is cleared.
Note that this option is only useful for widgets that do not exit immediately after using it because the strings displayed will be erased immediately after return from the widget.
This command can safely be called outside user defined widgets; if zle is active, the display will be refreshed, while if zle is not active, the command has no effect. In this case there will usually be no other arguments.
The status is zero if zle was active, else one.
As with the -R option, the string will be displayed below the command line; unlike the -R option, the string will not be put into the status line but will instead be printed normally below the prompt. This means that the string will still be displayed after the widget returns (until it is overwritten by subsequent commands).
This pushes the characters in the string onto the input stack of ZLE. After the widget currently executed finishes ZLE will behave as if the characters in the string were typed by the user.
As ZLE uses a stack, if this option is used repeatedly the last string pushed onto the stack will be processed first. However, the characters in each string will be processed in the order in which they appear in the string.
Selects the keymap named keymap. An error message will be displayed if there is no such keymap.
This keymap selection affects the interpretation of following keystrokes within this invocation of ZLE. Any following invocation (e.g., the next command line) will start as usual with the `main' keymap selected.
Only available if your system supports one of the `poll' or `select' system calls; most modern systems do.
Installs handler (the name of a shell function) to handle input from file descriptor fd. When zle is attempting to read data, it will examine both the terminal and the list of handled fd's. If data becomes available on a handled fd, zle will call handler with the fd which is ready for reading as the only argument. If the handler produces output to the terminal, it should call `zle -I' before doing so (see below). The handler should not attempt to read from the terminal. Note that zle makes no attempt to check whether this fd is actually readable when installing the handler. The user must make their own arrangements for handling the file descriptor when zle is not active.
Any number of handlers for any number of readable file descriptors may be installed. Installing a handler for an fd which is already handled causes the existing handler to be r> ] in-string command ...
bindkey's options can be divided into three categories: keymap selection, operation selection, and others. The keymap selection options are:
Selects keymap `emacs', and also links it to `main'.
Selects keymap `viins', and also links it to `main'.
Selects keymap `vicmd'.
The keymap specifies a keymap name.
If a keymap selection is required and none of the options above are used, the `main' keymap is used. Some operations do not permit a keymap to be selected, namely:
List all existing keymap names. If the -L option is also used, list in the form of bindkey commands to create the keymaps.
Delete all existing keymaps and reset to the default state.
Delete the named keymaps.
Make the new-keymap name an alias for old-keymap, so that both names refer to the same keymap. The names have equal standing; if either is deleted, the other remains. If there is already a keymap with the new-keymap name, it is deleted.
Create a new keymap, named new-keymap. If a keymap already has that name, it is deleted. If an old-keymap name is given, the new keymap is initialized to be a duplicate of it, otherwise the new keymap will be empty.
To use a newly created keymap, it should be linked to main. Hence the sequence of commands to create and use a new keymap `mymap' initialized from the emacs keymap (which remains unchanged) is:
bindkey -N mymap emacs bindkey -A mymap main |
Note that while `bindkey -A newmap main' will work when newmap is emacs or viins, it will not work for vicmd, as switching from vi insert to command mode becomes impossible.
The following operations act on the `main' keymap if no keymap selection option was given:
Add the built-in set of meta-key bindings to the selected keymap. Only keys that are unbound or bound to self-insert are affected.
Unbind the specified in-strings in the selected keymap. This is exactly equivalent to binding the strings to undefined-key.
When -R is also used, interpret the in-strings as ranges.
When -p is also used, the in-strings specify prefixes. Any binding that has the given in-string as a prefix, not including the binding for the in-string itself, if any, will be removed. For example,
bindkey -rpM viins '^[' |
will remove all bindings in the vi-insert keymap beginning with an escape character (probably cursor keys), but leave the binding for the escape character itself (probably vi-cmd-mode). This is incompatible with the option -R.
Bind each in-string to each out-string. When in-string is typed, out-string will be pushed back and treated as input to the line editor. When -R is also used, interpret the in-strings as ranges.
Bind each in-string to each command. When -R is used, interpret the in-strings as ranges.
List key bindings. If an in-string is specified, the binding of that string in the selected keymap is displayed. Otherwise, all key bindings in the selected keymap are displayed. (As a special case, if the -e or -v option is used alone, the keymap is not displayed - the implicit linking of keymaps is the only thing that happens.)
When the option -p is used, the in-string must be present. The listing shows all bindings which have the given key sequence as a prefix, not including any bindings for the key sequence itself.
When the -L option is used, the list is in the form of bindkey commands to create the key bindings.
When the -R option is used as noted above, a valid range consists of two characters, with an optional `-' between them. All characters between the two specified, inclusive, are bound as specified.
For either in-string or out-string, the following escape sequences are recognised:
bell character
backspace
escape
form feed
linefeed (newline)
carriage return
horizontal tab
vertical tab
character code in octal
character code in hexadecimal
character with meta bit set
control character
control character
In all other cases, `\' escapes the following character. Delete is written as `^?'. Note that `\M^?' and `^\M?' are not the same, and that (unlike emacs), the bindings `\M-X' and `\eX' are entirely distinct, although they are initialized to the same bindings by `bindkey -m'.
The value of the parameter name is loaded into the edit buffer, and the line editor is invoked. When the editor exits, name is set to the string value returned by the editor. When the -c flag is given, the parameter is created if it doesn't already exist. The -a flag may be given with -c to create an array parameter, or the -A flag to create an associative array. If the type of an existing parameter does not match the type to be created, the parameter is unset and recreated.
If an array or array slice is being edited, separator characters as defined in $IFS will be shown quoted with a backslash, as will backslashes themselves. Conversely, when the edited text is split into an array, a backslash quotes an immediately following separator character or backslash; no other special handling of backslashes, or any handling of quotes, is performed.
Individual elements of existing array or associative array parameters may be edited by using subscript syntax on name. New elements are created automatically, even without -c.
If the -p flag is given, the following string will be taken as the prompt to display at the left. If the -r flag is given, the following string gives the prompt to display at the right. If the -h flag is specified, the history can be accessed from ZLE. If the -e flag is given, typing ^D (Control-D) on an empty line causes vared to exit immediately with a non-zero return value.
The -M option gives a keymap to link to the main keymap during editing, and the -m option gives a keymap to link to the vicmd keymap during editing. For vi-style editing, this allows a pair of keymaps to override viins and vicmd. For emacs-style editing, only -M is normally needed but the -m option may still be used. On exit, the previous keymaps will be restored.
The zle builtin performs a number of different actions concerning ZLE.
With no options and no arguments, only the return status will be set. It is zero if ZLE is currently active and widgets could be invoked using this builtin command and non-zero otherwise. Note that even if non-zero status is returned, zle may still be active as part of the completion system; this does not allow direct calls to ZLE widgets.
Otherwise, which operation it performs depends on its options:
List all existing user-defined widgets. If the -L option is used, list in the form of zle commands to create the widgets.
When combined with the -a option, all widget names are listed, including the builtin ones. In this case the -L option is ignored.
If at least one string is given, nothing will be printed but the return status will be zero if all strings are names of existing widgets (or of user-defined widgets if the -a flag is not given) and non-zero if at least one string is not a name of an defined widget.
Delete the named widgets.
Make the new-widget name an alias for old-widget, so that both names refer to the same widget. The names have equal standing; if either is deleted, the other remains. If there is already a widget with the new-widget name, it is deleted.
Create a user-defined widget. If there is already a widget with the specified name, it is overwritten. When the new widget is invoked from within the editor, the specified shell function is called. If no function name is specified, it defaults to the same name as the widget. For further information, see the section Widgets in Zsh Line Editor.
Create a user-defined completion widget named widget. The completion widget will behave like the built-in completion-widget whose name is given as completion-widget. To generate the completions, the shell function function will be called. For further information, see Completion Widgets.
Redisplay the command line; this is to be called from within a user-defined widget to allow changes to become visible. If a display-string is given and not empty, this is shown in the status line (immediately below the line being edited).
If the optional strings are given they are listed below the prompt in the same way as completion lists are printed. If no strings are given but the -c option is used such a list is cleared.
Note that this option is only useful for widgets that do not exit immediately after using it because the strings displayed will be erased immediately after return from the widget.
This command can safely be called outside user defined widgets; if zle is active, the display will be refreshed, while if zle is not active, the command has no effect. In this case there will usually be no other arguments.
The status is zero if zle was active, else one.
As with the -R option, the string will be displayed below the command line; unlike the -R option, the string will not be put into the status line but will instead be printed normally below the prompt. This means that the string will still be displayed after the widget returns (until it is overwritten by subsequent commands).
This pushes the characters in the string onto the input stack of ZLE. After the widget currently executed finishes ZLE will behave as if the characters in the string were typed by the user.
As ZLE uses a stack, if this option is used repeatedly the last string pushed onto the stack will be processed first. However, the characters in each string will be processed in the order in which they appear in the string.
Selects the keymap named keymap. An error message will be displayed if there is no such keymap.
This keymap selection affects the interpretation of following keystrokes within this invocation of ZLE. Any following invocation (e.g., the next command line) will start as usual with the `main' keymap selected.
Only available if your system supports one of the `poll' or `select' system calls; most modern systems do.
Installs handler (the name of a shell function) to handle input from file descriptor fd. When zle is attempting to read data, it will examine both the terminal and the list of handled fd's. If data becomes available on a handled fd, zle will call handler with the fd which is ready for reading as the only argument. If the handler produces output to the terminal, it should call `zle -I' before doing so (see below). The handler should not attempt to read from the terminal. Note that zle makes no attempt to check whether this fd is actually readable when installing the handler. The user must make their own arrangements for handling the file descriptor when zle is not active.
Any number of handlers for any number of readable file descriptors may be installed. Installing a handler for an fd which is already handled causes the existing handler to be r> ] in-string command ...
bindkey's options can be divided into three categories: keymap selection, operation selection, and others. The keymap selection options are:
Selects keymap `emacs', and also links it to `main'.
Selects keymap `viins', and also links it to `main'.
Selects keymap `vicmd'.
The keymap specifies a keymap name.
If a keymap selection is required and none of the options above are used, the `main' keymap is used. Some operations do not permit a keymap to be selected, namely:
List all existing keymap names. If the -L option is also used, list in the form of bindkey commands to create the keymaps.
Delete all existing keymaps and reset to the default state.
Delete the named keymaps.
Make the new-keymap name an alias for old-keymap, so that both names refer to the same keymap. The names have equal standing; if either is deleted, the other remains. If there is already a keymap with the new-keymap name, it is deleted.
Create a new keymap, named new-keymap. If a keymap already has that name, it is deleted. If an old-keymap name is given, the new keymap is initialized to be a duplicate of it, otherwise the new keymap will be empty.
To use a newly created keymap, it should be linked to main. Hence the sequence of commands to create and use a new keymap `mymap' initialized from the emacs keymap (which remains unchanged) is:
bindkey -N mymap emacs bindkey -A mymap main |
Note that while `bindkey -A newmap main' will work when newmap is emacs or viins, it will not work for vicmd, as switching from vi insert to command mode becomes impossible.
The following operations act on the `main' keymap if no keymap selection option was given:
Add the built-in set of meta-key bindings to the selected keymap. Only keys that are unbound or bound to self-insert are affected.
Unbind the specified in-strings in the selected keymap. This is exactly equivalent to binding the strings to undefined-key.
When -R is also used, interpret the in-strings as ranges.
When -p is also used, the in-strings specify prefixes. Any binding that has the given in-string as a prefix, not including the binding for the in-string itself, if any, will be removed. For example,
bindkey -rpM viins '^[' |
will remove all bindings in the vi-insert keymap beginning with an escape character (probably cursor keys), but leave the binding for the escape character itself (probably vi-cmd-mode). This is incompatible with the option -R.
Bind each in-string to each out-string. When in-string is typed, out-string will be pushed back and treated as input to the line editor. When -R is also used, interpret the in-strings as ranges.
Bind each in-string to each command. When -R is used, interpret the in-strings as ranges.
List key bindings. If an in-string is specified, the binding of that string in the selected keymap is displayed. Otherwise, all key bindings in the selected keymap are displayed. (As a special case, if the -e or -v option is used alone, the keymap is not displayed - the implicit linking of keymaps is the only thing that happens.)
When the option -p is used, the in-string must be present. The listing shows all bindings which have the given key sequence as a prefix, not including any bindings for the key sequence itself.
When the -L option is used, the list is in the form of bindkey commands to create the key bindings.
When the -R option is used as noted above, a valid range consists of two characters, with an optional `-' between them. All characters between the two specified, inclusive, are bound as specified.
For either in-string or out-string, the following escape sequences are recognised:
bell character
backspace
escape
form feed
linefeed (newline)
carriage return
horizontal tab
vertical tab
character code in octal
character code in hexadecimal
character with meta bit set
control character
control character
In all other cases, `\' escapes the following character. Delete is written as `^?'. Note that `\M^?' and `^\M?' are not the same, and that (unlike emacs), the bindings `\M-X' and `\eX' are entirely distinct, although they are initialized to the same bindings by `bindkey -m'.
The value of the parameter name is loaded into the edit buffer, and the line editor is invoked. When the editor exits, name is set to the string value returned by the editor. When the -c flag is given, the parameter is created if it doesn't already exist. The -a flag may be given with -c to create an array parameter, or the -A flag to create an associative array. If the type of an existing parameter does not match the type to be created, the parameter is unset and recreated.
If an array or array slice is being edited, separator characters as defined in $IFS will be shown quoted with a backslash, as will backslashes themselves. Conversely, when the edited text is split into an array, a backslash quotes an immediately following separator character or backslash; no other special handling of backslashes, or any handling of quotes, is performed.
Individual elements of existing array or associative array parameters may be edited by using subscript syntax on name. New elements are created automatically, even without -c.
If the -p flag is given, the following string will be taken as the prompt to display at the left. If the -r flag is given, the following string gives the prompt to display at the right. If the -h flag is specified, the history can be accessed from ZLE. If the -e flag is given, typing ^D (Control-D) on an empty line causes vared to exit immediately with a non-zero return value.
The -M option gives a keymap to link to the main keymap during editing, and the -m option gives a keymap to link to the vicmd keymap during editing. For vi-style editing, this allows a pair of keymaps to override viins and vicmd. For emacs-style editing, only -M is normally needed but the -m option may still be used. On exit, the previous keymaps will be restored.
The zle builtin performs a number of different actions concerning ZLE.
With no options and no arguments, only the return status will be set. It is zero if ZLE is currently active and widgets could be invoked using this builtin command and non-zero otherwise. Note that even if non-zero status is returned, zle may still be active as part of the completion system; this does not allow direct calls to ZLE widgets.
Otherwise, which operation it performs depends on its options:
List all existing user-defined widgets. If the -L option is used, list in the form of zle commands to create the widgets.
When combined with the -a option, all widget names are listed, including the builtin ones. In this case the -L option is ignored.
If at least one string is given, nothing will be printed but the return status will be zero if all strings are names of existing widgets (or of user-defined widgets if the -a flag is not given) and non-zero if at least one string is not a name of an defined widget.
Delete the named widgets.
Make the new-widget name an alias for old-widget, so that both names refer to the same widget. The names have equal standing; if either is deleted, the other remains. If there is already a widget with the new-widget name, it is deleted.
Create a user-defined widget. If there is already a widget with the specified name, it is overwritten. When the new widget is invoked from within the editor, the specified shell function is called. If no function name is specified, it defaults to the same name as the widget. For further information, see the section Widgets in Zsh Line Editor.
Create a user-defined completion widget named widget. The completion widget will behave like the built-in completion-widget whose name is given as completion-widget. To generate the completions, the shell function function will be called. For further information, see Completion Widgets.
Redisplay the command line; this is to be called from within a user-defined widget to allow changes to become visible. If a display-string is given and not empty, this is shown in the status line (immediately below the line being edited).
If the optional strings are given they are listed below the prompt in the same way as completion lists are printed. If no strings are given but the -c option is used such a list is cleared.
Note that this option is only useful for widgets that do not exit immediately after using it because the strings displayed will be erased immediately after return from the widget.
This command can safely be called outside user defined widgets; if zle is active, the display will be refreshed, while if zle is not active, the command has no effect. In this case there will usually be no other arguments.
The status is zero if zle was active, else one.
As with the -R option, the string will be displayed below the command line; unlike the -R option, the string will not be put into the status line but will instead be printed normally below the prompt. This means that the string will still be displayed after the widget returns (until it is overwritten by subsequent commands).
This pushes the characters in the string onto the input stack of ZLE. After the widget currently executed finishes ZLE will behave as if the characters in the string were typed by the user.
As ZLE uses a stack, if this option is used repeatedly the last string pushed onto the stack will be processed first. However, the characters in each string will be processed in the order in which they appear in the string.
Selects the keymap named keymap. An error message will be displayed if there is no such keymap.
This keymap selection affects the interpretation of following keystrokes within this invocation of ZLE. Any following invocation (e.g., the next command line) will start as usual with the `main' keymap selected.
Only available if your system supports one of the `poll' or `select' system calls; most modern systems do.
Installs handler (the name of a shell function) to handle input from file descriptor fd. When zle is attempting to read data, it will examine both the terminal and the list of handled fd's. If data becomes available on a handled fd, zle will call handler with the fd which is ready for reading as the only argument. If the handler produces output to the terminal, it should call `zle -I' before doing so (see below). The handler should not attempt to read from the terminal. Note that zle makes no attempt to check whether this fd is actually readable when installing the handler. The user must make their own arrangements for handling the file descriptor when zle is not active.
Any number of handlers for any number of readable file descriptors may be installed. Installing a handler for an fd which is already handled causes the existing handler to be r> ] in-string command ...
bindkey's options can be divided into three categories: keymap selection, operation selection, and others. The keymap selection options are:
Selects keymap `emacs', and also links it to `main'.
Selects keymap `viins', and also links it to `main'.
Selects keymap `vicmd'.
The keymap specifies a keymap name.
If a keymap selection is required and none of the options above are used, the `main' keymap is used. Some operations do not permit a keymap to be selected, namely:
List all existing keymap names. If the -L option is also used, list in the form of bindkey commands to create the keymaps.
Delete all existing keymaps and reset to the default state.
Delete the named keymaps.
Make the new-keymap name an alias for old-keymap, so that both names refer to the same keymap. The names have equal standing; if either is deleted, the other remains. If there is already a keymap with the new-keymap name, it is deleted.
Create a new keymap, named new-keymap. If a keymap already has that name, it is deleted. If an old-keymap name is given, the new keymap is initialized to be a duplicate of it, otherwise the new keymap will be empty.
To use a newly created keymap, it should be linked to main. Hence the sequence of commands to create and use a new keymap `mymap' initialized from the emacs keymap (which remains unchanged) is:
bindkey -N mymap emacs bindkey -A mymap main |
Note that while `bindkey -A newmap main' will work when newmap is emacs or viins, it will not work for vicmd, as switching from vi insert to command mode becomes impossible.
The following operations act on the `main' keymap if no keymap selection option was given:
Add the built-in set of meta-key bindings to the selected keymap. Only keys that are unbound or bound to self-insert are affected.
Unbind the specified in-strings in the selected keymap. This is exactly equivalent to binding the strings to undefined-key.
When -R is also used, interpret the in-strings as ranges.
When -p is also used, the in-strings specify prefixes. Any binding that has the given in-string as a prefix, not including the binding for the in-string itself, if any, will be removed. For example,
bindkey -rpM viins '^[' |
will remove all bindings in the vi-insert keymap beginning with an escape character (probably cursor keys), but leave the binding for the escape character itself (probably vi-cmd-mode). This is incompatible with the option -R.
Bind each in-string to each out-string. When in-string is typed, out-string will be pushed back and treated as input to the line editor. When -R is also used, interpret the in-strings as ranges.
Bind each in-string to each command. When -R is used, interpret the in-strings as ranges.
List key bindings. If an in-string is specified, the binding of that string in the selected keymap is displayed. Otherwise, all key bindings in the selected keymap are displayed. (As a special case, if the -e or -v option is used alone, the keymap is not displayed - the implicit linking of keymaps is the only thing that happens.)
When the option -p is used, the in-string must be present. The listing shows all bindings which have the given key sequence as a prefix, not including any bindings for the key sequence itself.
When the -L option is used, the list is in the form of bindkey commands to create the key bindings.
When the -R option is used as noted above, a valid range consists of two characters, with an optional `-' between them. All characters between the two specified, inclusive, are bound as specified.
For either in-string or out-string, the following escape sequences are recognised:
bell character
backspace
escape
form feed
linefeed (newline)
carriage return
horizontal tab
vertical tab
character code in octal
character code in hexadecimal
character with meta bit set
control character
control character
In all other cases, `\' escapes the following character. Delete is written as `^?'. Note that `\M^?' and `^\M?' are not the same, and that (unlike emacs), the bindings `\M-X' and `\eX' are entirely distinct, although they are initialized to the same bindings by `bindkey -m'.
The value of the parameter name is loaded into the edit buffer, and the line editor is invoked. When the editor exits, name is set to the string value returned by the editor. When the -c flag is given, the parameter is created if it doesn't already exist. The -a flag may be given with -c to create an array parameter, or the -A flag to create an associative array. If the type of an existing parameter does not match the type to be created, the parameter is unset and recreated.
If an array or array slice is being edited, separator characters as defined in $IFS will be shown quoted with a backslash, as will backslashes themselves. Conversely, when the edited text is split into an array, a backslash quotes an immediately following separator character or backslash; no other special handling of backslashes, or any handling of quotes, is performed.
Individual elements of existing array or associative array parameters may be edited by using subscript syntax on name. New elements are created automatically, even without -c.
If the -p flag is given, the following string will be taken as the prompt to display at the left. If the -r flag is given, the following string gives the prompt to display at the right. If the -h flag is specified, the history can be accessed from ZLE. If the -e flag is given, typing ^D (Control-D) on an empty line causes vared to exit immediately with a non-zero return value.
The -M option gives a keymap to link to the main keymap during editing, and the -m option gives a keymap to link to the vicmd keymap during editing. For vi-style editing, this allows a pair of keymaps to override viins and vicmd. For emacs-style editing, only -M is normally needed but the -m option may still be used. On exit, the previous keymaps will be restored.
The zle builtin performs a number of different actions concerning ZLE.
With no options and no arguments, only the return status will be set. It is zero if ZLE is currently active and widgets could be invoked using this builtin command and non-zero otherwise. Note that even if non-zero status is returned, zle may still be active as part of the completion system; this does not allow direct calls to ZLE widgets.
Otherwise, which operation it performs depends on its options:
List all existing user-defined widgets. If the -L option is used, list in the form of zle commands to create the widgets.
When combined with the -a option, all widget names are listed, including the builtin ones. In this case the -L option is ignored.
If at least one string is given, nothing will be printed but the return status will be zero if all strings are names of existing widgets (or of user-defined widgets if the -a flag is not given) and non-zero if at least one string is not a name of an defined widget.
Delete the named widgets.
Make the new-widget name an alias for old-widget, so that both names refer to the same widget. The names have equal standing; if either is deleted, the other remains. If there is already a widget with the new-widget name, it is deleted.
Create a user-defined widget. If there is already a widget with the specified name, it is overwritten. When the new widget is invoked from within the editor, the specified shell function is called. If no function name is specified, it defaults to the same name as the widget. For further information, see the section Widgets in Zsh Line Editor.
Create a user-defined completion widget named widget. The completion widget will behave like the built-in completion-widget whose name is given as completion-widget. To generate the completions, the shell function function will be called. For further information, see Completion Widgets.
Redisplay the command line; this is to be called from within a user-defined widget to allow changes to become visible. If a display-string is given and not empty, this is shown in the status line (immediately below the line being edited).
If the optional strings are given they are listed below the prompt in the same way as completion lists are printed. If no strings are given but the -c option is used such a list is cleared.
Note that this option is only useful for widgets that do not exit immediately after using it because the strings displayed will be erased immediately after return from the widget.
This command can safely be called outside user defined widgets; if zle is active, the display will be refreshed, while if zle is not active, the command has no effect. In this case there will usually be no other arguments.
The status is zero if zle was active, else one.
As with the -R option, the string will be displayed below the command line; unlike the -R option, the string will not be put into the status line but will instead be printed normally below the prompt. This means that the string will still be displayed after the widget returns (until it is overwritten by subsequent commands).
This pushes the characters in the string onto the input stack of ZLE. After the widget currently executed finishes ZLE will behave as if the characters in the string were typed by the user.
As ZLE uses a stack, if this option is used repeatedly the last string pushed onto the stack will be processed first. However, the characters in each string will be processed in the order in which they appear in the string.
Selects the keymap named keymap. An error message will be displayed if there is no such keymap.
This keymap selection affects the interpretation of following keystrokes within this invocation of ZLE. Any following invocation (e.g., the next command line) will start as usual with the `main' keymap selected.
Only available if your system supports one of the `poll' or `select' system calls; most modern systems do.
Installs handler (the name of a shell function) to handle input from file descriptor fd. When zle is attempting to read data, it will examine both the terminal and the list of handled fd's. If data becomes available on a handled fd, zle will call handler with the fd which is ready for reading as the only argument. If the handler produces output to the terminal, it should call `zle -I' before doing so (see below). The handler should not attempt to read from the terminal. Note that zle makes no attempt to check whether this fd is actually readable when installing the handler. The user must make their own arrangements for handling the file descriptor when zle is not active.
Any number of handlers for any number of readable file descriptors may be installed. Installing a handler for an fd which is already handled causes the existing handler to be r> ] in-string command ...
bindkey's options can be divided into three categories: keymap selection, operation selection, and others. The keymap selection options are:
Selects keymap `emacs', and also links it to `main'.
Selects keymap `viins', and also links it to `main'.
Selects keymap `vicmd'.
The keymap specifies a keymap name.
If a keymap selection is required and none of the options above are used, the `main' keymap is used. Some operations do not permit a keymap to be selected, namely:
List all existing keymap names. If the -L option is also used, list in the form of bindkey commands to create the keymaps.
Delete all existing keymaps and reset to the default state.
Delete the named keymaps.
Make the new-keymap name an alias for old-keymap, so that both names refer to the same keymap. The names have equal standing; if either is deleted, the other remains. If there is already a keymap with the new-keymap name, it is deleted.
Create a new keymap, named new-keymap. If a keymap already has that name, it is deleted. If an old-keymap name is given, the new keymap is initialized to be a duplicate of it, otherwise the new keymap will be empty.
To use a newly created keymap, it should be linked to main. Hence the sequence of commands to create and use a new keymap `mymap' initialized from the emacs keymap (which remains unchanged) is:
bindkey -N mymap emacs bindkey -A mymap main |
Note that while `bindkey -A newmap main' will work when newmap is emacs or viins, it will not work for vicmd, as switching from vi insert to command mode becomes impossible.
The following operations act on the `main' keymap if no keymap selection option was given:
Add the built-in set of meta-key bindings to the selected keymap. Only keys that are unbound or bound to self-insert are affected.
Unbind the specified in-strings in the selected keymap. This is exactly equivalent to binding the strings to undefined-key.
When -R is also used, interpret the in-strings as ranges.
When -p is also used, the in-strings specify prefixes. Any binding that has the given in-string as a prefix, not including the binding for the in-string itself, if any, will be removed. For example,
bindkey -rpM viins '^[' |
will remove all bindings in the vi-insert keymap beginning with an escape character (probably cursor keys), but leave the binding for the escape character itself (probably vi-cmd-mode). This is incompatible with the option -R.
Bind each in-string to each out-string. When in-string is typed, out-string will be pushed back and treated as input to the line editor. When -R is also used, interpret the in-strings as ranges.
Bind each in-string to each command. When -R is used, interpret the in-strings as ranges.
List key bindings. If an in-string is specified, the binding of that string in the selected keymap is displayed. Otherwise, all key bindings in the selected keymap are displayed. (As a special case, if the -e or -v option is used alone, the keymap is not displayed - the implicit linking of keymaps is the only thing that happens.)
When the option -p is used, the in-string must be present. The listing shows all bindings which have the given key sequence as a prefix, not including any bindings for the key sequence itself.
When the -L option is used, the list is in the form of bindkey commands to create the key bindings.
When the -R option is used as noted above, a valid range consists of two characters, with an optional `-' between them. All characters between the two specified, inclusive, are bound as specified.
For either in-string or out-string, the following escape sequences are recognised:
bell character
backspace
escape
form feed
linefeed (newline)
carriage return
horizontal tab
vertical tab
character code in octal
character code in hexadecimal
character with meta bit set
control character
control character
In all other cases, `\' escapes the following character. Delete is written as `^?'. Note that `\M^?' and `^\M?' are not the same, and that (unlike emacs), the bindings `\M-X' and `\eX' are entirely distinct, although they are initialized to the same bindings by `bindkey -m'.
The value of the parameter name is loaded into the edit buffer, and the line editor is invoked. When the editor exits, name is set to the string value returned by the editor. When the -c flag is given, the parameter is created if it doesn't already exist. The -a flag may be given with -c to create an array parameter, or the -A flag to create an associative array. If the type of an existing parameter does not match the type to be created, the parameter is unset and recreated.
If an array or array slice is being edited, separator characters as defined in $IFS will be shown quoted with a backslash, as will backslashes themselves. Conversely, when the edited text is split into an array, a backslash quotes an immediately following separator character or backslash; no other special handling of backslashes, or any handling of quotes, is performed.
Individual elements of existing array or associative array parameters may be edited by using subscript syntax on name. New elements are created automatically, even without -c.
If the -p flag is given, the following string will be taken as the prompt to display at the left. If the -r flag is given, the following string gives the prompt to display at the right. If the -h flag is specified, the history can be accessed from ZLE. If the -e flag is given, typing ^D (Control-D) on an empty line causes vared to exit immediately with a non-zero return value.
The -M option gives a keymap to link to the main keymap during editing, and the -m option gives a keymap to link to the vicmd keymap during editing. For vi-style editing, this allows a pair of keymaps to override viins and vicmd. For emacs-style editing, only -M is normally needed but the -m option may still be used. On exit, the previous keymaps will be restored.
The zle builtin performs a number of different actions concerning ZLE.
With no options and no arguments, only the return status will be set. It is zero if ZLE is currently active and widgets could be invoked using this builtin command and non-zero otherwise. Note that even if non-zero status is returned, zle may still be active as part of the completion system; this does not allow direct calls to ZLE widgets.
Otherwise, which operation it performs depends on its options:
List all existing user-defined widgets. If the -L option is used, list in the form of zle commands to create the widgets.
When combined with the -a option, all widget names are listed, including the builtin ones. In this case the -L option is ignored.
If at least one string is given, nothing will be printed but the return status will be zero if all strings are names of existing widgets (or of user-defined widgets if the -a flag is not given) and non-zero if at least one string is not a name of an defined widget.
Delete the named widgets.
Make the new-widget name an alias for old-widget, so that both names refer to the same widget. The names have equal standing; if either is deleted, the other remains. If there is already a widget with the new-widget name, it is deleted.
Create a user-defined widget. If there is already a widget with the specified name, it is overwritten. When the new widget is invoked from within the editor, the specified shell function is called. If no function name is specified, it defaults to the same name as the widget. For further information, see the section Widgets in Zsh Line Editor.
Create a user-defined completion widget named widget. The completion widget will behave like the built-in completion-widget whose name is given as completion-widget. To generate the completions, the shell function function will be called. For further information, see Completion Widgets.
Redisplay the command line; this is to be called from within a user-defined widget to allow changes to become visible. If a display-string is given and not empty, this is shown in the status line (immediately below the line being edited).
If the optional strings are given they are listed below the prompt in the same way as completion lists are printed. If no strings are given but the -c option is used such a list is cleared.
Note that this option is only useful for widgets that do not exit immediately after using it because the strings displayed will be erased immediately after return from the widget.
This command can safely be called outside user defined widgets; if zle is active, the display will be refreshed, while if zle is not active, the command has no effect. In this case there will usually be no other arguments.
The status is zero if zle was active, else one.
As with the -R option, the string will be displayed below the command line; unlike the -R option, the string will not be put into the status line but will instead be printed normally below the prompt. This means that the string will still be displayed after the widget returns (until it is overwritten by subsequent commands).
This pushes the characters in the string onto the input stack of ZLE. After the widget currently executed finishes ZLE will behave as if the characters in the string were typed by the user.
As ZLE uses a stack, if this option is used repeatedly the last string pushed onto the stack will be processed first. However, the characters in each string will be processed in the order in which they appear in the string.
Selects the keymap named keymap. An error message will be displayed if there is no such keymap.
This keymap selection affects the interpretation of following keystrokes within this invocation of ZLE. Any following invocation (e.g., the next command line) will start as usual with the `main' keymap selected.
Only available if your system supports one of the `poll' or `select' system calls; most modern systems do.
Installs handler (the name of a shell function) to handle input from file descriptor fd. When zle is attempting to read data, it will examine both the terminal and the list of handled fd's. If data becomes available on a handled fd, zle will call handler with the fd which is ready for reading as the only argument. If the handler produces output to the terminal, it should call `zle -I' before doing so (see below). The handler should not attempt to read from the terminal. Note that zle makes no attempt to check whether this fd is actually readable when installing the handler. The user must make their own arrangements for handling the file descriptor when zle is not active.
Any number of handlers for any number of readable file descriptors may be installed. Installing a handler for an fd which is already handled causes the existing handler to be r> ] in-string command ...
bindkey's options can be divided into three categories: keymap selection, operation selection, and others. The keymap selection options are:
Selects keymap `emacs', and also links it to `main'.
Selects keymap `viins', and also links it to `main'.
Selects keymap `vicmd'.
The keymap specifies a keymap name.
If a keymap selection is required and none of the options above are used, the `main' keymap is used. Some operations do not permit a keymap to be selected, namely:
List all existing keymap names. If the -L option is also used, list in the form of bindkey commands to create the keymaps.
Delete all existing keymaps and reset to the default state.
Delete the named keymaps.
Make the new-keymap name an alias for old-keymap, so that both names refer to the same keymap. The names have equal standing; if either is deleted, the other remains. If there is already a keymap with the new-keymap name, it is deleted.
Create a new keymap, named new-keymap. If a keymap already has that name, it is deleted. If an old-keymap name is given, the new keymap is initialized to be a duplicate of it, otherwise the new keymap will be empty.
To use a newly created keymap, it should be linked to main. Hence the sequence of commands to create and use a new keymap `mymap' initialized from the emacs keymap (which remains unchanged) is:
bindkey -N mymap emacs bindkey -A mymap main |
Note that while `bindkey -A newmap main' will work when newmap is emacs or viins, it will not work for vicmd, as switching from vi insert to command mode becomes impossible.
The following operations act on the `main' keymap if no keymap selection option was given:
Add the built-in set of meta-key bindings to the selected keymap. Only keys that are unbound or bound to self-insert are affected.
Unbind the specified in-strings in the selected keymap. This is exactly equivalent to binding the strings to undefined-key.
When -R is also used, interpret the in-strings as ranges.
When -p is also used, the in-strings specify prefixes. Any binding that has the given in-string as a prefix, not including the binding for the in-string itself, if any, will be removed. For example,
bindkey -rpM viins '^[' |
will remove all bindings in the vi-insert keymap beginning with an escape character (probably cursor keys), but leave the binding for the escape character itself (probably vi-cmd-mode). This is incompatible with the option -R.
Bind each in-string to each out-string. When in-string is typed, out-string will be pushed back and treated as input to the line editor. When -R is also used, interpret the in-strings as ranges.
Bind each in-string to each command. When -R is used, interpret the in-strings as ranges.
List key bindings. If an in-string is specified, the binding of that string in the selected keymap is displayed. Otherwise, all key bindings in the selected keymap are displayed. (As a special case, if the -e or -v option is used alone, the keymap is not displayed - the implicit linking of keymaps is the only thing that happens.)
When the option -p is used, the in-string must be present. The listing shows all bindings which have the given key sequence as a prefix, not including any bindings for the key sequence itself.
When the -L option is used, the list is in the form of bindkey commands to create the key bindings.
When the -R option is used as noted above, a valid range consists of two characters, with an optional `-' between them. All characters between the two specified, inclusive, are bound as specified.
For either in-string or out-string, the following escape sequences are recognised:
bell character
backspace
escape
form feed
linefeed (newline)
carriage return
horizontal tab
vertical tab
character code in octal
character code in hexadecimal
character with meta bit set
control character
control character
In all other cases, `\' escapes the following character. Delete is written as `^?'. Note that `\M^?' and `^\M?' are not the same, and that (unlike emacs), the bindings `\M-X' and `\eX' are entirely distinct, although they are initialized to the same bindings by `bindkey -m'.
The value of the parameter name is loaded into the edit buffer, and the line editor is invoked. When the editor exits, name is set to the string value returned by the editor. When the -c flag is given, the parameter is created if it doesn't already exist. The -a flag may be given with -c to create an array parameter, or the -A flag to create an associative array. If the type of an existing parameter does not match the type to be created, the parameter is unset and recreated.
If an array or array slice is being edited, separator characters as defined in $IFS will be shown quoted with a backslash, as will backslashes themselves. Conversely, when the edited text is split into an array, a backslash quotes an immediately following separator character or backslash; no other special handling of backslashes, or any handling of quotes, is performed.
Individual elements of existing array or associative array parameters may be edited by using subscript syntax on name. New elements are created automatically, even without -c.
If the -p flag is given, the following string will be taken as the prompt to display at the left. If the -r flag is given, the following string gives the prompt to display at the right. If the -h flag is specified, the history can be accessed from ZLE. If the -e flag is given, typing ^D (Control-D) on an empty line causes vared to exit immediately with a non-zero return value.
The -M option gives a keymap to link to the main keymap during editing, and the -m option gives a keymap to link to the vicmd keymap during editing. For vi-style editing, this allows a pair of keymaps to override viins and vicmd. For emacs-style editing, only -M is normally needed but the -m option may still be used. On exit, the previous keymaps will be restored.