Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
152 lines (132 sloc) 5.27 KB
# Keys from emacs mode. Anything that doesn't conflict gets to stay.
bindkey -v # start with vi keys
autoload edit-command-line; zle -N edit-command-line
bindkey -M vicmd v edit-command-line
# The classics of emacs bindings:
bindkey "^A" beginning-of-line
bindkey "^B" backward-char
bindkey "^D" delete-char-or-list
bindkey "^E" end-of-line
bindkey "^F" forward-char
bindkey "^G" send-break
bindkey "^H" backward-delete-char
bindkey "^I" expand-or-complete
bindkey "^K" kill-line
bindkey "^N" down-line-or-history
bindkey "^P" up-line-or-history
bindkey "^R" history-incremental-search-backward
bindkey "^S" history-incremental-search-forward
bindkey "^T" transpose-chars
bindkey "^U" kill-whole-line
bindkey "^Y" yank
bindkey "^[b" backward-word
bindkey "^[f" forward-word
bindkey "^[d" kill-word
# And now, for some exciting ones, if you've only used vi keys…
bindkey "^[." insert-last-word # Alt+'.' gives !$'s value.
bindkey "^[?" which-command # Shows "which" output for the current command
bindkey "^[H" run-help # run "man" on current command (Alt+Shift+h)
bindkey -M vicmd "^[H" run-help
# Say you ran:
# % cd ~/src/foo
# % vim lib/foo.rb
# % rake test
#
# You could ^r to find the "cd ~/src/foo" line, then hit ^o twice to
# execute the subsequent commands.
bindkey "^O" accept-line-and-down-history
# Cut the contents of the line then paste when the next prompt appears.
# (kind of like backgrounding the current command line for 1 command)
bindkey "^Q" push-line
bindkey "^[Q" push-line
bindkey "^[q" push-line
bindkey -M vicmd "^[q" push-line
bindkey "^['" quote-line # Very useful. E.g. to echo a command into a file.
bindkey -M vicmd "^['" quote-line
# Searches history for the current command, then puts the line *after that*
# into the edit buffer. Funky but interesting.
bindkey "^X^N" infer-next-history
# Kinda like vim's ^O — one-shot vi cmd
bindkey "^X^V" vi-cmd-mode
# Run through line (or arg, depending on context) history
bindkey "^[N" history-search-forward
bindkey "^[n" history-search-forward
bindkey "^[P" history-search-backward
bindkey "^[p" history-search-backward
# duplicate the token to the left:
bindkey "^[^_" copy-prev-word
bindkey "^[ " expand-history
# Things that have more efficient bindings, but keeping for compatibility with
# people used to them:
bindkey "^X^B" vi-match-bracket # vi: %
bindkey "^X^F" vi-find-next-char # vi: f
bindkey "^X^J" vi-join # vi: J
bindkey "^X^K" kill-buffer # ^u^k
bindkey "^X^O" overwrite-mode # vi: R
bindkey "^X^U" undo # vi: u
bindkey "^Xu" undo
bindkey "^X=" what-cursor-position # Show char info, like vim ga + g^g
bindkey "^Xr" history-incremental-search-backward # Same as ^r
bindkey "^Xs" history-incremental-search-forward # Same as ^s # For stty ixon?
bindkey "^[^H" backward-kill-word # Same as ^w.
bindkey "^[^L" clear-screen # ^L
bindkey "^[^G" send-break # ^G
bindkey "^[<" beginning-of-buffer-or-history # gg
bindkey "^[>" end-of-buffer-or-history # G
bindkey "^[OA" up-line-or-history # ^p or vi: k
bindkey "^[[A" up-line-or-history # (same)
bindkey "^[OB" down-line-or-history # ^n or vi: j
bindkey "^[[B" down-line-or-history # (same)
bindkey "^[[C" forward-char # ^f or vi: l
bindkey "^[[D" backward-char # ^b or vi: h
bindkey "^[_" insert-last-word # Alt+.
bindkey "^_" undo
bindkey "^?" backward-delete-char
# Fined grained expansion vs. completion. (Tab is generally handier)
bindkey "^X*" expand-word # "Shell expansion of current word"
bindkey "^[!" expand-history # "History expansion on the edit buffer"
bindkey "^[^D" list-choices # Show, but don't complete, possible completions
bindkey "^Xg" list-expand # Show, but don't expand, expansion. (c.f., ^d)
bindkey "^XG" list-expand
# TODO: Learn about emacs-like marks handling and enable these:
#bindkey "^@" set-mark-command
#bindkey "^X^X" exchange-point-and-mark
#bindkey "^[\"" quote-region
#bindkey "^[G" get-line # "Pop the top line off the buffer stack and
#bindkey "^[w" copy-region-as-kill
#bindkey "^[y" yank-pop
# TODO: Learn these, too:
#bindkey "^[\$" spell-word
#bindkey "^[-" neg-argument # TODO: figure out how to use this
# And now, for the bummer of the story.
# Since that ^[x means Alt+x, zsh can't distinguish between the two. Maybe
# there's a way to get them to work without robbing the vi-key siblings.
#
# I tried KEYTIMEOUT and that was fail. (It nixes the ability to bind "^X;"
# (from zaw) and "di(" (from ./vim-keys)
#bindkey "^[a" accept-and-hold
#bindkey "^[c" capitalize-word
#bindkey "^[g" get-line
#bindkey "^[D" kill-word
#bindkey "^[h" run-help
#bindkey "^[A" accept-and-hold
#bindkey "^[C" capitalize-word
#bindkey "^[L" down-case-word
#bindkey "^[S" spell-word
#bindkey "^[T" transpose-words
#bindkey "^[U" up-case-word
#bindkey "^[l" down-case-word
#bindkey "^[s" spell-word
#bindkey "^[t" transpose-words
#bindkey "^[u" up-case-word
#bindkey "^[W" copy-region-as-kill
#bindkey "^[x" execute-named-cmd
#bindkey "^[z" execute-last-named-cmd
#bindkey "^[|" vi-goto-column
#bindkey "^[^?" backward-kill-word
#-----------------------------------------
# Docs for these widgets are kind of here:
# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html
# Some details are here:
# https://github.com/zsh-users/zsh/tree/master/Functions/Zle
# vim:ft=zsh