Add Emacs-like delete-horizontal-space and just-one-space key binds

This commit is contained in:
Adam Goldsmith 2023-04-11 14:01:54 -04:00
parent 108d8ac5a3
commit 645710c31d
1 changed files with 17 additions and 0 deletions

17
.zshrc
View File

@ -62,6 +62,23 @@ zstyle ':completion:*' matcher-list 'm:{[:lower:]-}={[:upper:]_} r:|[.]=**' '+l:
bindkey '^[[5~' history-substring-search-up
bindkey '^[[6~' history-substring-search-down
# equivalents of eponymous Emacs functions
# from https://unix.stackexchange.com/a/595157
delete-horizontal-space() {
emulate -L zsh
set -o extendedglob
LBUFFER=${LBUFFER%%[[:blank:]]##}
RBUFFER=${RBUFFER##[[:blank:]]##}
}
zle -N delete-horizontal-space
bindkey '\e\\' delete-horizontal-space
just-one-space() {
delete-horizontal-space
LBUFFER="$LBUFFER "
}
zle -N just-one-space
bindkey '\e ' just-one-space
# Inserts 'sudo ' at the beginning of the line.
function prepend-sudo() {
if [[ "$BUFFER" != su(do|)\ * ]]; then