Skip to content

Instantly share code, notes, and snippets.

@kmorey
Created April 8, 2013 16:50

Revisions

  1. kmorey created this gist Apr 8, 2013.
    91 changes: 91 additions & 0 deletions mykeys.plugin.zsh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,91 @@
    # TODO: Explain what some of this does..

    bindkey -e
    bindkey '\ew' kill-region
    bindkey -s '\el' "ls\n"
    bindkey '^r' history-incremental-search-backward
    bindkey "^[[5~" up-line-or-history
    bindkey "^[[6~" down-line-or-history

    # make search up and down work, so partially type and hit up/down to find relevant stuff
    bindkey '^[[A' up-line-or-search
    bindkey '^[[B' down-line-or-search

    bindkey "^[[H" beginning-of-line
    bindkey "^[[1~" beginning-of-line
    bindkey "^[OH" beginning-of-line
    bindkey "^[[F" end-of-line
    bindkey "^[[4~" end-of-line
    bindkey "^[OF" end-of-line
    bindkey ' ' magic-space # also do history expansion on space

    bindkey "^[[1;5C" forward-word
    bindkey "^[[1;5D" backward-word

    bindkey '^[[Z' reverse-menu-complete

    # Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~
    bindkey '^?' backward-delete-char
    bindkey "^[[3~" delete-char
    bindkey "^[3;5~" delete-char
    bindkey "\e[3~" delete-char

    # consider emacs keybindings:

    #bindkey -e ## emacs key bindings
    #
    #bindkey '^[[A' up-line-or-search
    #bindkey '^[[B' down-line-or-search
    #bindkey '^[^[[C' emacs-forward-word
    #bindkey '^[^[[D' emacs-backward-word
    #
    #bindkey -s '^X^Z' '%-^M'
    #bindkey '^[e' expand-cmd-path
    #bindkey '^[^I' reverse-menu-complete
    #bindkey '^X^N' accept-and-infer-next-history
    #bindkey '^W' kill-region
    #bindkey '^I' complete-word
    ## Fix weird sequence that rxvt produces
    #bindkey -s '^[[Z' '\t'
    #

    autoload up-line-or-beginning-search
    autoload down-line-or-beginning-search
    zle -N up-line-or-beginning-search
    zle -N down-line-or-beginning-search

    bindkey -v # set vim bindings
    #http://zshwiki.org/home/zle/bindkeys

    typeset -A key

    key[Home]=${terminfo[khome]}
    key[End]=${terminfo[kend]}
    key[Insert]=${terminfo[kich1]}
    key[Delete]=${terminfo[kdch1]}
    key[Up]=${terminfo[kcuu1]}
    key[Down]=${terminfo[kcud1]}
    key[Left]=${terminfo[kcub1]}
    key[Right]=${terminfo[kcuf1]}
    key[PageUp]=${terminfo[kpp]}
    key[PageDown]=${terminfo[knp]}
    key[Enter]=${terminfo[kent]}

    # setup key accordingly
    [[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
    [[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
    [[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode
    [[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
    [[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-beginning-search
    [[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-beginning-search
    [[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
    [[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
    [[ -n "${key[Enter]}" ]] && bindkey "${key[Enter]}" enter

    # Finally, make sure the terminal is in application mode, when zle is
    # active. Only then are the values from $terminfo valid.
    zle-line-init () { echoti smkx }
    zle-line-finish () { echoti rmkx }

    zle -N zle-line-init
    zle -N zle-line-finish