zsh: better, more vim-like keybinds

This commit is contained in:
Henrik Lissner 2015-12-10 01:59:01 -05:00
parent 432d096887
commit 0b318ff932
2 changed files with 59 additions and 42 deletions

View file

@ -28,10 +28,6 @@ unsetopt BG_NICE # Don't run all background jobs at a lower priority.
unsetopt HUP # Don't kill jobs on shell exit. unsetopt HUP # Don't kill jobs on shell exit.
unsetopt CHECK_JOBS # Don't report on jobs when shell exit. unsetopt CHECK_JOBS # Don't report on jobs when shell exit.
# Allow command line editing in an external editor.
autoload -Uz edit-command-line
zle -N edit-command-line
export GIT_MERGE_AUTOEDIT=no export GIT_MERGE_AUTOEDIT=no
unsetopt CORRECT_ALL unsetopt CORRECT_ALL

View file

@ -1,51 +1,59 @@
bindkey -v bindkey -v
# Allow command line editing in an external editor.
autoload -Uz edit-command-line
zle -N edit-command-line
bindkey '^ ' edit-command-line bindkey '^ ' edit-command-line
bindkey '`' autopair-insert # zsh-autopair
bindkey '"' autopair-insert bindkey '`' autopair-insert
bindkey "'" autopair-insert bindkey '"' autopair-insert
bindkey '(' autopair-insert bindkey "'" autopair-insert
bindkey '[' autopair-insert bindkey '(' autopair-insert
bindkey '{' autopair-insert bindkey '[' autopair-insert
bindkey '^?' autopair-delete bindkey '{' autopair-insert
bindkey '^?' autopair-delete # smart backspace
bindkey -M viins '^w' backward-kill-word bindkey '^n' history-substring-search-down
bindkey -M viins '^[w' forward-word bindkey '^p' history-substring-search-up
bindkey -M viins '^[b' backward-word bindkey '^s' history-incremental-pattern-search-backward
bindkey '^u' undo
bindkey '^r' redo
bindkey '^w' backward-kill-word
bindkey '^b' backward-word
bindkey '^e' forward-word
bindkey '^q' push-line-or-edit
bindkey '^a' beginning-of-line
bindkey '^e' end-of-line
bindkey -M vicmd 'yy' vi-yank-whole-line # Shift + Tab
bindkey -M vicmd 'Y' vi-yank-eol bindkey -M viins '^[[Z' reverse-menu-complete
bindkey -M viins ' ' magic-space bindkey -M viins ' ' magic-space
bindkey -M viins 'jk' vi-cmd-mode bindkey -M viins 'jk' vi-cmd-mode
bindkey -M viins '^x^f' fasd-complete-f # C-x C-f to do fasd-complete-f (only files) # Vim keymaps
bindkey -M viins '^x^d' fasd-complete-d # C-x C-d to do fasd-complete-d (only directories) bindkey -M vicmd 'ga' what-cursor-position
bindkey -M vicmd 'gg' beginning-of-history
bindkey -M viins '^q' push-line-or-edit bindkey -M vicmd 'G ' end-of-history
bindkey -M vicmd "^[[3~" delete-char bindkey -M vicmd '^k' kill-line
bindkey "^[[3~" delete-char bindkey -M vicmd '?' history-incremental-pattern-search-forward
bindkey "^[3;5~" delete-char bindkey -M vicmd '/' history-incremental-pattern-search-backward
bindkey -M vicmd ':' execute-named-cmd
bindkey -M vicmd "?" history-incremental-pattern-search-backward # Page up / Page down
bindkey -M vicmd "/" history-incremental-pattern-search-forward bindkey -M vicmd 'H' run-help
bindkey -M vicmd 'u' undo
bindkey -M vicmd 'U' redo
bindkey -M vicmd 'yy' vi-yank-whole-line
bindkey -M vicmd 'Y' vi-yank-eol
# bind UP and DOWN arrow keys # bind UP and DOWN arrow keys
zmodload zsh/terminfo
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down
# bind UP and DOWN arrow keys (compatibility fallback
# for Ubuntu 12.04, Fedora 21, and MacOSX 10.9 users)
bindkey '^[[A' history-substring-search-up bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down bindkey '^[[B' history-substring-search-down
# Edit command in an external editor. # Completion
bindkey -M vicmd "R" edit-command-line 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)
# # Undo/Redo
bindkey -M vicmd "u" undo
bindkey -M vicmd "$key_info[Control]R" redo
# 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() {
@ -62,10 +70,23 @@ if [ -n "$TMUX" ]; then
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 '^n' tmux-pane-words-prefix bindkey -M viins '^x^n' tmux-pane-words-prefix
bindkey -M viins '^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
# Fixes
bindkey -M vicmd "^[[3~" delete-char
bindkey "^[[3~" delete-char
bindkey "^[3;5~" delete-char
# Fix vimmish ESC
export KEYTIMEOUT=10 # just enough time for jk
bindkey -sM vicmd '^[' '^G'
bindkey -rM viins '^X'
bindkey -M viins '^X,' _history-complete-newer \
'^X/' _history-complete-older \
'^X`' _bash_complete-word