Copyright (C) 2000-2012 |
GNU Info (zsh.info)Zle BuiltinsZle Builtins ============ 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 [ OPTIONS ] -l bindkey [ OPTIONS ] -d bindkey [ OPTIONS ] -D KEYMAP ... bindkey [ OPTIONS ] -A OLD-KEYMAP NEW-KEYMAP bindkey [ OPTIONS ] -N NEW-KEYMAP [ OLD-KEYMAP ] bindkey [ OPTIONS ] -m bindkey [ OPTIONS ] -r IN-STRING ... bindkey [ OPTIONS ] -s IN-STRING OUT-STRING ... bindkey [ OPTIONS ] IN-STRING COMMAND ... bindkey [ OPTIONS ] [ IN-STRING ] bindkey's options can be divided into three categories: keymap selection, operation selection, and others. The keymap selection options are: -e Selects keymap `emacs', and also links it to `main'. -v Selects keymap `viins', and also links it to `main'. -a Selects keymap `vicmd'. -M The first non-option argument is used as a keymap name, and does not otherwise count as an argument. 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: -l List all existing keymap names. If the -L option is also used, list in the form of bindkey commands to create the keymaps. -d Delete all existing keymaps and reset to the default state. -D KEYMAP ... Delete the named KEYMAPs. -A OLD-KEYMAP NEW-KEYMAP 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. -N NEW-KEYMAP [ OLD-KEYMAP ] 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: -m 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. -r IN-STRING ... 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. -s IN-STRING OUT-STRING ... 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. IN-STRING COMMAND ... Bind each IN-STRING to each COMMAND. When -R is used, interpret the IN-STRINGs as ranges. [ IN-STRING ] 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: \a bell character \b backspace \e, \E escape \f form feed \n linefeed (newline) \r carriage return \t horizontal tab \v vertical tab \NNN character code in octal \xNN character code in hexadecimal \M[-]X character with meta bit set \C[-]X control character ^X 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'. vared [ -Aache ] [ -p PROMPT ] [ -r RPROMPT ] NAME 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. zle -l [ -L | -a ] [ STRING ... ] zle -D WIDGET ... zle -A OLD-WIDGET NEW-WIDGET zle -N WIDGET [ FUNCTION ] zle -C WIDGET COMPLETION-WIDGET FUNCTION zle -R [ -c ] [ DISPLAY-STRING ] [ STRING ... ] zle -M STRING zle -U STRING zle -I zle WIDGET [ -n NUM ] [ -N ] ARGS ... zle The zle builtin performs a number of different actions concerning ZLE. Which operation it performs depends on its options: -l [ -L | -a ] 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. -D WIDGET ... Delete the named WIDGETs. -A OLD-WIDGET NEW-WIDGET 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. -N WIDGET [ FUNCTION ] 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 Note: Zsh Line Editor. -C WIDGET COMPLETION-WIDGET FUNCTION 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 Note: Completion Widgets. -R [ -c ] [ DISPLAY-STRING ] [ STRING ... ] 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. -M STRING 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). -U STRING 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. -I Unusually, this option is only useful _outside_ ordinary widget functions. It invalidates the current zle display in preparation for output; usually this will be from a trap function. It has no effect if zle is not active. When a trap exits, the shell checks to see if the display needs restoring, hence the following will print output in such a way as not to disturb the line being edited: TRAPUSR1() { # Invalidate zle display zle -I # Show output print Hello } Note that there are better ways of manipulating the display from within zle widgets. In general, the trap function may need to test whether zle is loaded before using this method; if it is not, there is no point in loading it specially since the line editor will not be active. The status is zero if zle was active, else one. WIDGET [ -n NUM ] [ -N ] ARGS ... Invoke the specified widget. This can only be done when ZLE is active; normally this will be within a user-defined widget. With the options -n and -N, the current numerical argument will be saved and then restored after the call to widget; `-n NUM' sets the numerical argument temporarily to NUM, while `-N' sets it to the default, i.e. as if there were none. Any further arguments will be passed to the widget. If it is a shell function, these are passed down as positional parameters; for builtin widgets it is up to the widget in question what it does with them. Currently arguments are only handled by the incremental-search commands, the history-search-forward and -backward and the corresponding functions prefixed by vi-, and by universal-argument. No error is flagged if the command does not use the arguments, or only uses some of them. The return status reflects the success or failure of the operation carried out by the widget, or if it is a user-defined widget the return status of the shell function. A non-zero return status causes the shell to beep when the widget exits, unless the BEEP options was unset or the widget was called via the zle command. Thus if a user defined widget requires an immediate beep, it should call the beep widget directly. 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 if ZLE is not active. automatically generated by info2www version 1.2.2.9 |