zsh: Reverse alias expansion between space and ctrl space

Previously, <space> would expand any alias and all environment
variables while <c-space> would simply put a normal space on the zle
without performing any expansion.

This change reverses this, so that nothing gets expanded by default
_but_ if the user wants to specifically expand something the option
exists to simply use <c-space> to see the expanded version.
This commit is contained in:
Marty Oehme 2025-12-08 13:02:35 +01:00
parent 5c565b61e1
commit d9c88d99f3
Signed by: Marty
GPG key ID: 4E535BC19C61886E

View file

@ -171,16 +171,17 @@ alias history="fc -l -d -D"
### Glob Alias expansion
# Expand aliases inline - see http://blog.patshead.com/2012/11/automatically-expaning-zsh-global-aliases---simplified.html
globalias() {
if [[ $LBUFFER =~ [A-Z0-9]+$ ]]; then
zle _expand_alias
zle expand-word
fi
zle self-insert
zle _expand_alias
zle expand-word
zle magic-space
}
zle -N globalias
bindkey " " globalias
bindkey "^ " magic-space # control-space to bypass completion
bindkey -M isearch " " magic-space # normal space during searches
bindkey -M emacs "^ " globalias # expand anything when hitting <c-space>
bindkey -M viins "^ " globalias # only expand when in insert mode for vi
bindkey -M emacs " " self-insert
bindkey -M viins " " self-insert
bindkey -M vicmd " " self-insert # space puts a space, even in cmd mode
bindkey -M isearch " " self-insert # normal space during searches
# allow inserting previous arguments in the current zle input
# see https://stackoverflow.com/a/34861762
@ -234,8 +235,6 @@ bindkey -M vicmd 'C' _run-cdi
# insert-mode keybind is above, using regular fzf sourcing
bindkey -M vicmd 'T' fzf-file-widget
# space puts a space, even in cmd mode
bindkey -a ' ' magic-space
# always allow backspace/delete to remove letters
bindkey '^?' backward-delete-char
bindkey -a '^?' backward-delete-char