helm/config/zsh/keybinds.zsh

128 lines
3.7 KiB
Bash
Raw Permalink Normal View History

2017-10-03 10:55:26 -07:00
# The surround module wasn't working if KEYTIMEOUT was <= 10. Specifically,
# (delete|change)-surround immediately abort into insert mode if KEYTIMEOUT <=
# 8. If <= 10, then add-surround does the same. At 11, all these issues vanish.
# Very strange!
2015-12-31 06:04:42 -08:00
export KEYTIMEOUT=15
2015-12-22 01:32:00 -08:00
autoload -U is-at-least
2015-12-20 20:39:11 -08:00
## vi-mode ###############
2016-10-19 07:56:37 -07:00
bindkey -v
2015-12-20 20:39:11 -08:00
bindkey -M viins 'jk' vi-cmd-mode
2017-10-06 03:15:48 -07:00
bindkey -M viins ' ' magic-space
2015-12-20 20:39:11 -08:00
# bindkey -M viins '^I' expand-or-complete-prefix
# surround
autoload -Uz surround
zle -N delete-surround surround
zle -N add-surround surround
zle -N change-surround surround
bindkey -a cs change-surround
bindkey -a ds delete-surround
bindkey -a ys add-surround
# <5.0.8 doesn't have visual map
2015-12-22 01:23:58 -08:00
if is-at-least 5.0.8; then
bindkey -M visual S add-surround
# add vimmish text-object support to zsh
autoload -U select-quoted; zle -N select-quoted
for m in visual viopp; do
for c in {a,i}{\',\",\`}; do
bindkey -M $m $c select-quoted
2015-12-20 20:39:11 -08:00
done
done
autoload -U select-bracketed; zle -N select-bracketed
for m in visual viopp; do
for c in {a,i}${(s..)^:-'()[]{}<>bB'}; do
bindkey -M $m $c select-bracketed
2015-12-20 20:39:11 -08:00
done
done
2015-12-22 01:23:58 -08:00
fi
2015-12-20 20:39:11 -08:00
# Open current prompt in external editor
2015-12-20 20:39:11 -08:00
autoload -Uz edit-command-line; zle -N edit-command-line
2015-12-09 22:59:01 -08:00
bindkey '^ ' edit-command-line
2015-12-10 02:38:28 -08:00
bindkey -M viins '^n' history-substring-search-down
bindkey -M viins '^p' history-substring-search-up
bindkey -M viins '^s' history-incremental-pattern-search-backward
bindkey -M viins '^u' backward-kill-line
2015-12-10 02:38:28 -08:00
bindkey -M viins '^w' backward-kill-word
bindkey -M viins '^b' backward-word
2016-05-29 11:20:02 -07:00
bindkey -M viins '^f' forward-word
2015-12-20 20:39:11 -08:00
bindkey -M viins '^g' push-line-or-edit
2015-12-10 02:38:28 -08:00
bindkey -M viins '^a' beginning-of-line
bindkey -M viins '^e' end-of-line
2016-04-12 13:57:47 -07:00
bindkey -M viins '^d' push-line-or-edit
2014-08-21 00:28:28 -07:00
2015-12-26 23:31:25 -08:00
bindkey -M vicmd '^k' kill-line
bindkey -M vicmd 'H' run-help
2015-12-09 22:59:01 -08:00
# Shift + Tab
bindkey -M viins '^[[Z' reverse-menu-complete
2014-09-05 13:55:50 -07:00
2015-06-18 13:16:54 -07:00
# bind UP and DOWN arrow keys
bindkey '^[[A' history-substring-search-up
2015-06-19 14:42:38 -07:00
bindkey '^[[B' history-substring-search-down
2015-06-18 13:16:54 -07:00
# C-z to toggle current process (background/foreground)
2015-12-12 13:59:07 -08:00
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg"
zle accept-line
else
zle push-input
zle clear-screen
fi
2015-12-12 13:59:07 -08:00
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
2015-12-20 20:39:11 -08:00
# Omni-Completion
2015-12-09 22:59:01 -08:00
bindkey -M viins '^x^f' fasd-complete-f # C-x C-f to do fasd-complete-f (only files)
bindkey -M viins '^x^d' fasd-complete-d # C-x C-d to do fasd-complete-d (only directories)
2014-09-05 13:55:50 -07:00
# Completing words in buffer in tmux
if [ -n "$TMUX" ]; then
_tmux_pane_words() {
local expl
local -a w
if [[ -z "$TMUX_PANE" ]]; then
_message "not running inside tmux!"
return 1
fi
w=( ${(u)=$(tmux capture-pane \; show-buffer \; delete-buffer)} )
_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-anywhere complete-word _generic
bindkey -M viins '^x^n' tmux-pane-words-prefix
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):*' ignore-line current
zstyle ':completion:tmux-pane-words-anywhere:*' matcher-list 'b:=* m:{A-Za-z}={a-zA-Z}'
2014-09-05 13:55:50 -07:00
fi
2015-12-09 22:59:01 -08:00
2015-12-09 23:01:07 -08:00
# Vim's C-x C-l in zsh
history-beginning-search-backward-then-append() {
zle history-beginning-search-backward
zle vi-add-eol
2015-12-09 23:01:07 -08:00
}
zle -N history-beginning-search-backward-then-append
bindkey -M viins '^x^l' history-beginning-search-backward-then-append
# Fix the DEL key
2015-12-09 22:59:01 -08:00
bindkey -M vicmd "^[[3~" delete-char
bindkey "^[[3~" delete-char
2015-12-09 22:59:01 -08:00
# Fix vimmish ESC
bindkey -sM vicmd '^[' '^G'
bindkey -rM viins '^X'
bindkey -M viins '^X,' _history-complete-newer \
'^X/' _history-complete-older \
'^X`' _bash_complete-word
2015-12-20 20:39:11 -08:00