GNU Info

Info Node: (zsh.info)Zle Widgets

(zsh.info)Zle Widgets


Prev: Zle Builtins Up: Zsh Line Editor
Enter node , (file) or (file)node

Widgets
=======

All actions in the editor are performed by `widgets'.  A widget's job is
simply to perform some small action.  The ZLE commands that key
sequences in keymaps are bound to are in fact widgets.  Widgets can be
user-defined or built in.

The standard widgets built in to ZLE are listed in Standard Widgets
below.  Other built-in widgets can be defined by other modules (see
Note: Zsh Modules).  Each built-in widget has two names: its normal
canonical name, and the same name preceded by a `.'.  The `.' name is
special: it can't be rebound to a different widget.  This makes the
widget available even when its usual name has been redefined.

User-defined widgets are defined using `zle -N', and implemented as
shell functions.  When the widget is executed, the corresponding shell
function is executed, and can perform editing (or other) actions.  It
is recommended that user-defined widgets should not have names starting
with `.'.

User-Defined Widgets
====================

User-defined widgets, being implemented as shell functions, can execute
any normal shell command.  They can also run other widgets (whether
built-in or user-defined) using the zle builtin command.  The standard
input of the function is closed to prevent external commands from
unintentionally blocking ZLE by reading from the terminal, but read -k
or read -q can be used to read characters.  Finally, they can examine
and edit the ZLE buffer being edited by reading and setting the special
parameters described below.

These special parameters are always available in widget functions, but
are not in any way special outside ZLE.  If they have some normal value
outside ZLE, that value is temporarily inaccessible, but will return
when the widget function exits.  These special parameters in fact have
local scope, like parameters created in a function using local.

Inside completion widgets and traps called while ZLE is active, these
parameters are available read-only.

BUFFER (scalar)
     The entire contents of the edit buffer.  If it is written to, the
     cursor remains at the same offset, unless that would put it
     outside the buffer.

BUFFERLINES
     The number of screen lines needed for the edit buffer currently
     displayed on screen (i.e. without any changes to the preceding
     parameters done after the last redisplay).

CURSOR (integer)
     The offset of the cursor, within the edit buffer.  This is in the
     range 0 to $#BUFFER, and is by definition equal to $#LBUFFER.
     Attempts to move the cursor outside the buffer will result in the
     cursor being moved to the appropriate end of the buffer.

HISTNO (integer)
     The current history number.

KEYS (scalar)
     The keys typed to invoke this widget, as a literal string.

LASTWIDGET (scalar)
     The name of the last widget that was executed.

LBUFFER (scalar)
     The part of the buffer that lies to the left of the cursor
     position.  If it is assigned to, only that part of the buffer is
     replaced, and the cursor remains between the new $LBUFFER and the
     old $RBUFFER.

MARK (integer)
     Like CURSOR, but for the mark.

NUMERIC (integer)
     The numeric argument. If no numeric argument was given, this
     parameter is unset. When this is set inside a widget function,
     builtin widgets called with the zle builtin command will use the
     value assigned. If it is unset inside a widget function, builtin
     widgets called behave as if no numeric argument was given.

PENDING (integer)
     The number of bytes pending for input, i.e. the number of bytes
     which have already been typed and can immediately be read. On
     systems where the shell is not able to get this information, this
     parameter will always have a value of zero.

PREBUFFER (scalar)
     In a multi-line input at the secondary prompt, this read-only
     parameter contains the contents of the lines before the one the
     cursor is currently in.

RBUFFER (scalar)
     The part of the buffer that lies to the right of the cursor
     position.  If it is assigned to, only that part of the buffer is
     replaced, and the cursor remains between the old $LBUFFER and the
     new $RBUFFER.

WIDGET (scalar)
     The name of the widget currently being executed.

Standard Widgets
================

The following is a list of all the standard widgets, and their default
bindings in emacs mode, vi command mode and vi insert mode (the
`emacs', `vicmd' and `viins' keymaps, respectively).

Note that cursor keys are bound to movement keys in all three keymaps;
the shell assumes that the cursor keys send the key sequences reported
by the terminal-handling library (termcap or terminfo).  The key
sequences shown in the list are those based on the VT100, common on
many modern terminals, but in fact these are not necessarily bound.  In
the case of the viins keymap, the initial escape character of the
sequences serves also to return to the vicmd keymap: whether this
happens is determined by the KEYTIMEOUT parameter, see Note:
Parameters.

Movement
History Control
Modifying Text
Arguments
Completion
Miscellaneous

automatically generated by info2www version 1.2.2.9