Appearance
Widgets and key bindings
By default
- Space expands abbreviations
- CtrlSpace is a normal space
- Enter expands and accepts abbreviations
(In incremental search mode, Space is a normal space and CtrlSpace expands abbreviations.)
There are three available widgets:
Widget | Behavior | Default binding |
---|---|---|
abbr-expand | If following an abbreviation, expands it | Not bound |
abbr-expand-and-accept | If following an abbreviation, expands it (with abbr-expand ). Then accepts the line | Enter |
abbr-expand-and-insert | If following an abbreviation, expands it (with abbr-expand ). Then appends the binding | Space in normal mode, CtrlSpace in search mode |
TIP
If the expansion cursor placement system is enabled, you can make abbr-expand-and-accept
behave like abbr-expand
on a per-abbreviation basis by appending the expansion cursor marker to the expansion. Learn more in Cursor placement.
abbr-expand-and-space
was deprecated in v5.4.0 and dropped in v6.0.0. Use abbr-expand-and-insert
instead.
zsh-abbr also binds CtrlSpace ("^ "
) to magic-space
and, in search mode, Space (-M isearch " "
) to magic-space
.
In the following example, additional bindings are added such that Ctrle expands abbreviations without adding a trailing space and Ctrla has the same behavior as Space.
shell
# .zshrc
bindkey "^E" abbr-expand
bindkey "^A" abbr-expand-and-insert
To prevent the creation of the default bindings, set ABBR_DEFAULT_BINDINGS
to 0
before initializing zsh-abbr. In the following example, CtrlSpace expands abbreviations and Space is not bound to any zsh-abbr widget.
shell
# .zshrc
ABBR_DEFAULT_BINDINGS=0
bindkey "^ " abbr-expand-and-insert
# load zsh-abbr here
Alternative keymaps
By default, zsh-abbr is only enabled for the default keymap. To enable a widget for another keymap, run bindkey -M
. For example, the following extends zsh-abbr's default behavior to the viins
keymap:
shell
# .zshrc
bindkey -M viins " " abbr-expand-and-insert
bindkey -M viins "^ " magic-space
bindkey -M viins "^M" abbr-expand-and-accept