From 645710c31d5f38b612447b807a90694a561b7378 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 11 Apr 2023 14:01:54 -0400 Subject: [PATCH] Add Emacs-like delete-horizontal-space and just-one-space key binds --- .zshrc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.zshrc b/.zshrc index d899656..9046a95 100644 --- a/.zshrc +++ b/.zshrc @@ -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