shell/zsh: reformat keybinds.zsh & fix visual map in older zsh

This commit is contained in:
Henrik Lissner 2018-01-01 02:12:06 -05:00
parent feea559aec
commit 566a187f3d
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -20,22 +20,24 @@ zle -N change-surround surround
bindkey -a cs change-surround bindkey -a cs change-surround
bindkey -a ds delete-surround bindkey -a ds delete-surround
bindkey -a ys add-surround bindkey -a ys add-surround
bindkey -M visual S add-surround
# add vimmish text-object support to zsh # <5.0.8 doesn't have visual map
if is-at-least 5.0.8; then if is-at-least 5.0.8; then
autoload -U select-quoted; zle -N select-quoted bindkey -M visual S add-surround
for m in visual viopp; do
for c in {a,i}{\',\",\`}; do # add vimmish text-object support to zsh
bindkey -M $m $c select-quoted autoload -U select-quoted; zle -N select-quoted
done for m in visual viopp; do
for c in {a,i}{\',\",\`}; do
bindkey -M $m $c select-quoted
done done
autoload -U select-bracketed; zle -N select-bracketed done
for m in visual viopp; do autoload -U select-bracketed; zle -N select-bracketed
for c in {a,i}${(s..)^:-'()[]{}<>bB'}; do for m in visual viopp; do
bindkey -M $m $c select-bracketed for c in {a,i}${(s..)^:-'()[]{}<>bB'}; do
done bindkey -M $m $c select-bracketed
done done
done
fi fi
# Open current prompt in external editor # Open current prompt in external editor
@ -66,13 +68,13 @@ bindkey '^[[B' history-substring-search-down
# C-z to toggle current process (background/foreground) # C-z to toggle current process (background/foreground)
fancy-ctrl-z () { fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg" BUFFER="fg"
zle accept-line zle accept-line
else else
zle push-input zle push-input
zle clear-screen zle clear-screen
fi fi
} }
zle -N fancy-ctrl-z zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z bindkey '^Z' fancy-ctrl-z
@ -82,32 +84,32 @@ bindkey -M viins '^x^f' fasd-complete-f # C-x C-f to do fasd-complete-f (only f
bindkey -M viins '^x^d' fasd-complete-d # C-x C-d to do fasd-complete-d (only directories) bindkey -M viins '^x^d' fasd-complete-d # C-x C-d to do fasd-complete-d (only directories)
# Completing words in buffer in tmux # Completing words in buffer in tmux
if [ -n "$TMUX" ]; then if [ -n "$TMUX" ]; then
_tmux_pane_words() { _tmux_pane_words() {
local expl local expl
local -a w local -a w
if [[ -z "$TMUX_PANE" ]]; then if [[ -z "$TMUX_PANE" ]]; then
_message "not running inside tmux!" _message "not running inside tmux!"
return 1 return 1
fi fi
w=( ${(u)=$(tmux capture-pane \; show-buffer \; delete-buffer)} ) w=( ${(u)=$(tmux capture-pane \; show-buffer \; delete-buffer)} )
_wanted values expl 'words from current tmux pane' compadd -a w _wanted values expl 'words from current tmux pane' compadd -a w
} }
zle -C tmux-pane-words-prefix complete-word _generic zle -C tmux-pane-words-prefix complete-word _generic
zle -C tmux-pane-words-anywhere complete-word _generic zle -C tmux-pane-words-anywhere complete-word _generic
bindkey -M viins '^x^n' tmux-pane-words-prefix bindkey -M viins '^x^n' tmux-pane-words-prefix
bindkey -M viins '^x^o' tmux-pane-words-anywhere bindkey -M viins '^x^o' tmux-pane-words-anywhere
zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' completer _tmux_pane_words zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' completer _tmux_pane_words
zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' ignore-line current zstyle ':completion:tmux-pane-words-(prefix|anywhere):*' ignore-line current
zstyle ':completion:tmux-pane-words-anywhere:*' matcher-list 'b:=* m:{A-Za-z}={a-zA-Z}' zstyle ':completion:tmux-pane-words-anywhere:*' matcher-list 'b:=* m:{A-Za-z}={a-zA-Z}'
fi fi
# Vim's C-x C-l in zsh # Vim's C-x C-l in zsh
history-beginning-search-backward-then-append() { history-beginning-search-backward-then-append() {
zle history-beginning-search-backward zle history-beginning-search-backward
zle vi-add-eol zle vi-add-eol
} }
zle -N history-beginning-search-backward-then-append zle -N history-beginning-search-backward-then-append
bindkey -M viins '^x^l' history-beginning-search-backward-then-append bindkey -M viins '^x^l' history-beginning-search-backward-then-append
@ -120,6 +122,6 @@ bindkey "^[[3~" delete-char
bindkey -sM vicmd '^[' '^G' bindkey -sM vicmd '^[' '^G'
bindkey -rM viins '^X' bindkey -rM viins '^X'
bindkey -M viins '^X,' _history-complete-newer \ bindkey -M viins '^X,' _history-complete-newer \
'^X/' _history-complete-older \ '^X/' _history-complete-older \
'^X`' _bash_complete-word '^X`' _bash_complete-word