If the ZLE
option is set (it is by default)
and the shell input is attached to the terminal, the user
is allowed 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.
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
viins
vicmd
.safe
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 eitor 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.
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. No timeout is done if the prefix string is not bound.
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.
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.
There are 162 standard widgets built in to ZLE (see sectref(Standard Widgets)).
Other built-in widgets can be defined by other modules (see
sectref(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, 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.
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
.
BUFFER
(scalar)
CURSOR
(integer)
$#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.
LBUFFER
(scalar)
$LBUFFER
and the old $RBUFFER
.
RBUFFER
(scalar)
$LBUFFER
and the new $RBUFFER
.
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).
vi-backward-blank-word
(unbound) (B) (unbound)
backward-char
(^B ESC-[D) (unbound) (unbound)
vi-backward-char
(unbound) (^H h ^?) (unbound)
backward-word
(ESC-B ESC-b) (unbound) (unbound)
emacs-backward-word
vi-backward-word
(unbound) (b) (unbound)
beginning-of-line
(^A) (unbound) (unbound)
vi-beginning-of-line
end-of-line
(^E) (unbound) (unbound)
vi-end-of-line
(unbound) ($) (unbound)
vi-forward-blank-word
(unbound) (W) (unbound)
vi-forward-blank-word-end
(unbound) (E) (unbound)
forward-char
(^F ESC-[C) (unbound) (unbound)
vi-forward-char
(unbound) (space l) (unbound)
vi-find-next-char
(^X^F) (f) (unbound)
vi-find-next-char-skip
(unbound) (t) (unbound)
vi-find-prev-char
(unbound) (F) (unbound)
vi-find-prev-char-skip
(unbound) (T) (unbound)
vi-first-non-blank
(unbound) (^) (unbound)
vi-forward-word
(unbound) (w) (unbound)
forward-word
(ESC-F ESC-f) (unbound) (unbound)
WORDCHARS
parameter.
emacs-forward-word
vi-forward-word-end
(unbound) (e) (unbound)
vi-goto-column
(ESC-|) (|) (unbound)
vi-goto-mark
(unbound) (`) (unbound)
vi-goto-mark-line
(unbound) (') (unbound)
vi-repeat-find
(unbound) (;) (unbound)
vi-find
command.
vi-rev-repeat-find
(unbound) (,) (unbound)
vi-find
command in the opposite direction.
beginning-of-buffer-or-history
(ESC-<) (unbound) (unbound)
beginning-of-line-hist
beginning-of-history
down-line-or-history
(^N ESC-[B) (j) (unbound)
vi-down-line-or-history
(unbound) (+) (unbound)
down-line-or-search
down-history
(unbound) (^N) (unbound)
history-beginning-search-backward
end-of-buffer-or-history
(ESC->) (unbound) (unbound)
end-of-line-hist
end-of-history
vi-fetch-history
(unbound) (G) (unbound)
history-incremental-search-backward
(^R ^Xr) (unbound) (unbound)
^
' to anchor the
search to the beginning of the line.
A restricted set of editing functions
is available in the mini-buffer. An interrupt signal, as defined by the stty
setting, will stop the search and go back to the original line. An undefined
key will have the same effect. The supported functions are:
backward-delete-char
,
vi-backward-delete-char
,
clear-screen
,
redisplay
,
quoted-insert
,
vi-quoted-insert
,
accept-and-hold
,
accept-and-infer-next-history
,
accept-line
and
accept-line-and-down-history
.
magic-space
just inserts a space.
vi-cmd-mode
toggles between the `main
' and `vicmd
' keymaps;
the `main
' keymap (insert mode) will be selected initially.
history-incremental-search-backward
will get the
next occurrence of the contents of the mini-buffer.
history-incremental-search-forward
inverts the sense of the search.
vi-repeat-search
and vi-rev-repeat-search
are similarly supported.
The direction of the search is indicated in the mini-buffer.
Any multi-character string
that is not bound to one of the above functions will beep and interrupt the
search, leaving the last found line in the buffer. Any single character that
is not bound to one of the above functions, or self-insert
or
self-insert-unmeta
, will have the same effect but the function will be
executed.
history-incremental-search-forward
(^S ^Xs) (unbound) (unbound)
^
' to anchor the
search to the beginning of the line. The functions available in the
mini-buffer are the same as for history-incremental-search-backward
.
history-search-backward
(ESC-P ESC-p) (unbound) (unbound)
vi-history-search-backward
(unbound) (/) (unbound)
^
' to anchor the search to the
beginning of the line.
A restricted set of editing functions is available in
the mini-buffer. An interrupt signal, as defined by the stty setting, will
stop the search.
The functions available in the mini-buffer are:
accept-line
,
backward-delete-char
,
vi-backward-delete-char
,
backward-kill-word
,
vi-backward-kill-word
,
clear-screen
,
redisplay
,
quoted-insert
and
vi-quoted-insert
.
vi-cmd-mode
is treated the same as accept-line, and
magic-space
is treated as a space.
Any other character that is not bound to self-insert or
self-insert-unmeta will beep and be ignored. If the function is called from vi
command mode, the bindings of the current insert mode will be used.
history-search-forward
(ESC-N ESC-n) (unbound) (unbound)
vi-history-search-forward
(unbound) (?) (unbound)
^
' to anchor the search to the
beginning of the line. The functions available in the mini-buffer are the same
as for vi-history-search-backward
.
infer-next-history
(^X^N) (unbound) (unbound)
insert-last-word
(ESC-_ ESC-.) (unbound) (unbound)
vi-repeat-search
(unbound) (n) (unbound)
vi-rev-repeat-search
(unbound) (N) (unbound)
up-line-or-history
(^P ESC-[A) (k) (unbound)
vi-up-line-or-history
(unbound) (-) (unbound)
up-line-or-search
up-history
(unbound) (^P) (unbound)
history-beginning-search-forward
vi-add-eol
(unbound) (A) (unbound)
vi-add-next
(unbound) (a) (unbound)
backward-delete-char
(^H ^?) (unbound) (unbound)
vi-backward-delete-char
(unbound) (X) (^H)
backward-delete-word
backward-kill-line
backward-kill-word
(^W ESC-^H ESC-^?) (unbound) (unbound)
vi-backward-kill-word
(unbound) (unbound) (^W)
capitalize-word
(ESC-C ESC-c) (unbound) (unbound)
vi-change
(unbound) (c) (unbound)
vi-change
, change the current line.
vi-change-eol
(unbound) (C) (unbound)
vi-change-whole-line
(unbound) (S) (unbound)
copy-region-as-kill
(ESC-W ESC-w) (unbound) (unbound)
copy-prev-word
(ESC-^_) (unbound) (unbound)
vi-delete
(unbound) (d) (unbound)
vi-delete
, kill the current line.
delete-char
vi-delete-char
(unbound) (x) (unbound)
delete-word
down-case-word
(ESC-L ESC-l) (unbound) (unbound)
kill-word
(ESC-D ESC-d) (unbound) (unbound)
gosmacs-transpose-chars
vi-indent
(unbound) (>) (unbound)
vi-insert
(unbound) (i) (unbound)
vi-insert-bol
(unbound) (I) (unbound)
vi-join
(^X^J) (J) (unbound)
kill-line
(^K) (unbound) (unbound)
vi-kill-line
(unbound) (unbound) (^U)
vi-kill-eol
(unbound) (D) (unbound)
kill-region
kill-buffer
(^X^K) (unbound) (unbound)
kill-whole-line
(^U) (unbound) (unbound)
vi-match-bracket
(^X^B) (%) (unbound)
{}
, ()
or []
) that
matches the one under the cursor.
If the cursor is not on a bracket character, move forward without going
past the end of the line to find one, and then go to the matching bracket.
vi-open-line-above
(unbound) (O) (unbound)
vi-open-line-below
(unbound) (o) (unbound)
vi-oper-swap-case
vi-oper-swap-case
,
swap the case of all characters on the current line.
overwrite-mode
(^X^O) (unbound) (unbound)
vi-put-before
(unbound) (P) (unbound)
vi-put-after
(unbound) (p) (unbound)
quoted-insert
(^V) (unbound) (unbound)
vi-quoted-insert
(unbound) (unbound) (^Q ^V)
^
' at the cursor position, and
insert the next character typed into the buffer literally.
An interrupt character will not be inserted.
quote-line
(ESC-') (unbound) (unbound)
'
' character at the
beginning and the end, and convert all `'
' characters
to `'\''
'.
quote-region
(ESC-") (unbound) (unbound)
vi-replace
(unbound) (R) (unbound)
vi-repeat-change
(unbound) (.) (unbound)
vi-replace-chars
(unbound) (r) (unbound)
self-insert
(printable characters) (unbound) (printable characters and some control characters)
self-insert-unmeta
(ESC-^I ESC-^J ESC-^M) (unbound) (unbound)
vi-substitute
(unbound) (s) (unbound)
vi-swap-case
(unbound) (~) (unbound)
transpose-chars
(^T) (unbound) (unbound)
transpose-words
(ESC-T ESC-t) (unbound) (unbound)
vi-unindent
(unbound) (<) (unbound)
up-case-word
(ESC-U ESC-u) (unbound) (unbound)
yank
(^Y) (unbound) (unbound)
yank-pop
(ESC-y) (unbound) (unbound)
yank
or yank-pop
.
vi-yank
(unbound) (y) (unbound)
vi-yank
, copy the current line.
vi-yank-whole-line
(unbound) (Y) (unbound)
vi-yank-eol
digit-argument
(ESC-0..ESC-9) (1-9) (unbound)
vi-digit-or-beginning-of-line
.
neg-argument
(ESC--) (unbound) (unbound)
universal-argument
accept-and-menu-complete
complete-word
delete-char-or-list
(^D) (unbound) (unbound)
expand-cmd-path
expand-or-complete
(TAB) (unbound) (TAB)
expand-or-complete-prefix
expand-history
(ESC-space ESC-!) (unbound) (unbound)
expand-word
(^X*) (unbound) (unbound)
list-choices
(ESC-^D) (^D =) (^D)
list-expand
(^Xg ^XG) (^G) (^G)
magic-space
menu-complete
complete-word
, except that menu completion is used.
See the MENU_COMPLETE
option.
menu-expand-or-complete
expand-or-complete
, except that menu completion is used.
reverse-menu-complete
menu-complete
, except that if
a menu completion is already in progress, move to the previous
completion rather than the next.
accept-and-hold
(ESC-A ESC-a) (unbound) (unbound)
accept-and-infer-next-history
accept-line
(^J ^M) (^J ^M) (^J ^M)
accept-line-and-down-history
(^O) (unbound) (unbound)
vi-cmd-mode
(^X^V) (unbound) (^[)
vicmd
' keymap.
Yes, this is bound by default in emacs mode.
vi-caps-lock-panic
clear-screen
(^L ESC-^L) (^L) (^L)
describe-key-briefly
exchange-point-and-mark
(^X^X) (unbound) (unbound)
execute-named-cmd
(ESC-x) (unbound) (unbound)
backward-delete-char
,
vi-backward-delete-char
,
clear-screen
,
redisplay
,
quoted-insert
,
vi-quoted-insert
,
backward-kill-word
,
vi-backward-kill-word
,
kill-whole-line
,
vi-kill-line
,
backward-kill-line
,
list-choices
,
delete-char-or-list
,
complete-word
,
accept-line
,
expand-or-complete
and
expand-or-complete-prefix
.
kill-region
kills the last word,
and vi-cmd-mode is treated the same as accept-line.
The space and tab characters, if not bound to one of
these functions, will complete the name and then list the
possibilities if the AUTO_LIST
option is set.
Any other character that is not bound to self-insert
or
self-insert-unmeta
will beep and be ignored.
The bindings of the current insert mode will be used.
execute-last-named-cmd
(ESC-z) (unbound) (unbound)
execute-named-cmd
.
get-line
(ESC-G ESC-g) (unbound) (unbound)
pound-insert
(unbound) (#) (unbound)
INTERACTIVE_COMMENTS
option must be set
for this to have any usefulness.
vi-pound-insert
INTERACTIVE_COMMENTS
option must be set
for this to have any usefulness.
push-input
PS1
) prompt.
If the current parser construct is only a single line, this is exactly
like push-line
.
Next time the editor starts up or is popped with get-line
, the
construct will be popped off the top of the buffer stack and loaded
into the editing buffer.
push-line
(^Q ESC-Q ESC-q) (unbound) (unbound)
push-line-or-edit
PS1
) prompt, equivalent to push-line
.
At a secondary (PS2
) prompt, move the entire current multiline
construct into the editor buffer.
The latter is equivalent to push-input
followed by get-line
.
redisplay
(unbound) (^R) (^R)
send-break
(^G ESC-^G) (unbound) (unbound)
execute-named-command
, or the
editor itself, e.g. if you are in vared
. Otherwise abort the parsing of
the current line.
run-help
(ESC-H ESC-h) (unbound) (unbound)
run-help
cmd', where cmd is the current
command. run-help
is normally aliased to man.
vi-set-buffer
(unbound) (") (unbound)
"a
to "z
and the nine `queued' buffers "1
to "9
. The named buffers can also
be specified as "A
to "Z
.
When a buffer is specified for a cut command, the text being cut replaces
the previous contents of the specified buffer. If a named buffer
is specified using a capital, the newly cut text is appended to the buffer
instead of overwriting it.
If no buffer is specified for a cut command, "1
is used, and the
contents of "1
to "8
are each shifted along one buffer; the contents of
"9
is lost.
vi-set-mark
(unbound) (m) (unbound)
set-mark-command
(^@) (unbound) (unbound)
spell-word
(ESC-$ ESC-S ESC-s) (unbound) (unbound)
undefined-key
undo
(^_ ^Xu ^X^U) (unbound) (unbound)
redo
vi-undo-change
(unbound) (u) (unbound)
what-cursor-position
(^X=) (unbound) (unbound)
where-is
which-command
(ESC-?) (unbound) (unbound)
which-command
cmd'. where cmd is the current
command. which-command
is normally aliased to whence.
vi-digit-or-beginning-of-line
(unbound) (0) (unbound)
Go to the first, previous, next, last section, table of contents.