zle
Zsh line editor builtin
TLDR
Define a new widget from a shell function
SYNOPSIS
zle [-lLaD] [widget ...]
zle -N widget [function]
zle -C widget completion-widget function
zle -R [-c] [display-string] [string ...]
zle -M string
zle -U string
zle -K keymap
zle -F [-Lw] [fd [handler]]
zle widget [-n num] [-f flag] [-Nw] [-K keymap] [-- args ...]
DESCRIPTION
zle is a builtin command of zsh that controls the Zsh Line Editor, the interactive command-line editing subsystem. It manages widgets (named editing actions), keymaps, display control, and the edit buffer. When called with no arguments, it returns zero if ZLE is currently active.
ZLE activates automatically in interactive zsh sessions. It operates in multiline mode (default) or single-line mode (when the SINGLE_LINE_ZLE option is set). Special parameters like BUFFER, CURSOR, LBUFFER, and RBUFFER allow widget functions to manipulate the edit buffer directly.
PARAMETERS
-N widget [function]
Define a new user-defined widget backed by a shell function. If function is omitted, defaults to the widget name-C widget completion-widget function
Create a user-defined completion widget inheriting behavior from an existing builtin completion widget-l [-L | -a]
List user-defined widgets. -L: format as zle commands. -a: include builtins-D widget ...
Delete named user-defined widgets-A old-widget new-widget
Create an alias; both names refer to the same widget-R [-c] [display-string] [string ...]
Redisplay the command line. Optional display-string appears in status line. -c clears completion lists-M string
Display a message string below the command line that persists after the widget returns-U string
Push characters onto ZLE's input stack for processing after the current widget finishes-K keymap
Select the named keymap for subsequent keystrokes-F [-Lw] [fd [handler]]
Install or remove a handler for a file descriptor. -w: handler is a widget. -L: list handlers-I
Invalidate the current display before external output-f flag ...
Set flags on the current widget: yank, yankbefore, kill, vichange, nolast
CONFIGURATION
ZLE is configured primarily through .zshrc using bindkey commands and zle -N widget definitions. The KEYTIMEOUT parameter (default 40, in hundredths of a second) controls how long ZLE waits for multi-character key sequences. Hook widgets like zle-line-init, zle-line-finish, and zle-keymap-select run automatically at specific events.
Example custom widget that prepends sudo:
BUFFER="sudo $BUFFER"
CURSOR+=5
}
zle -N prepend-sudo
bindkey '^s' prepend-sudo
KEYMAPS
ZLE provides eight built-in keymaps:
emacs -- Emacs-style editing
viins -- Vi insert mode
vicmd -- Vi command mode
viopp -- Vi operator-pending mode
visual -- Vi visual selection mode
isearch -- Incremental search mode
command -- Command name reading mode
.safe -- Immutable fallback keymap
The main keymap links to either emacs or viins depending on the EDITOR environment variable, or can be set with bindkey -e (emacs) or bindkey -v (vi).
CAVEATS
zle is only available inside zsh and is not a POSIX command or available in bash. Widgets can only be invoked when ZLE is active in interactive mode. Widget shell functions run with stdin redirected to /dev/null. Built-in widgets have a dot-prefixed variant (e.g., .end-of-line) that remains accessible even when the widget is overridden.
HISTORY
ZLE is a fundamental component of zsh, the Z Shell, originally written by Paul Falstad in 1990 at Princeton University. It provides zsh with sophisticated line editing modeled after both Emacs and vi editing modes but is zsh's own independent implementation with a widget-based architecture, distinct from GNU Readline used by bash.

