From 68cec79d32baeb96efc357ba94c0bfe5b4059c90 Mon Sep 17 00:00:00 2001 From: Kyle West Date: Mon, 30 Jan 2012 22:51:58 -0500 Subject: [PATCH 1/5] Added documentation to key bindings. Conflicts: lib/key-bindings.zsh --- lib/key-bindings.zsh | 50 -------------------------------------------- 1 file changed, 50 deletions(-) diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh index 5f499f3e8..e69de29bb 100644 --- a/lib/key-bindings.zsh +++ b/lib/key-bindings.zsh @@ -1,50 +0,0 @@ -# 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' -# From f7708d4181374cfbd223e071f7253018f28e5509 Mon Sep 17 00:00:00 2001 From: Kyle West Date: Mon, 30 Jan 2012 23:04:06 -0500 Subject: [PATCH 2/5] forgot to save before committing. doh --- lib/key-bindings.zsh | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh index e69de29bb..195bbb38e 100644 --- a/lib/key-bindings.zsh +++ b/lib/key-bindings.zsh @@ -0,0 +1,54 @@ +# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html +# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins +# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets + +bindkey -e # Use emacs key bindings + +bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark +bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls +bindkey -s '\e.' '..\n' # [Esc-.] - run command: .. (up directory) +bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line. +bindkey '^[[5~' up-line-or-history # [PageUp] - Up a line of history +bindkey '^[[6~' down-line-or-history # [PageDown] - Down a line of history + +bindkey '^[[A' up-line-or-search # start typing + [Up-Arrow] - fuzzy find history forward +bindkey '^[[B' down-line-or-search # start typing + [Down-Arrow] - fuzzy find history backward + +bindkey '^[[H' beginning-of-line # [Home] - Go to beginning of line +bindkey '^[[1~' beginning-of-line # [Home] - Go to beginning of line +bindkey '^[OH' beginning-of-line # [Home] - Go to beginning of line +bindkey '^[[F' end-of-line # [End] - Go to end of line +bindkey '^[[4~' end-of-line # [End] - Go to end of line +bindkey '^[OF' end-of-line # [End] - Go to end of line + +bindkey ' ' magic-space # [Space] - do history expansion + +bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word +bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word + +bindkey '^[[Z' reverse-menu-complete # [TODO] - Perform menu completion, like menu-complete, except that if a menu completion is already in progress, move to the previous completion rather than the next. + +# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~ +bindkey '^?' backward-delete-char # [Delete] - delete backward +bindkey '^[[3~' delete-char # [fn-Delete] - delete forward +bindkey '^[3;5~' delete-char # [TODO] - delete forward +bindkey '\e[3~' delete-char # [TODO] - delete forward + +# 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' +# From 3839c6e9e62a2671b1d3f5662e4d2bc3984c3f9e Mon Sep 17 00:00:00 2001 From: Mat Schaffer Date: Sat, 17 Mar 2012 22:03:01 -0300 Subject: [PATCH 3/5] Don't clobber standard Esc+. behavior Esc+. works as "last arg" on both bash and zsh. Seems like a shame to introduce a new standard. Conflicts: lib/key-bindings.zsh --- lib/key-bindings.zsh | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh index 195bbb38e..8168c8d90 100644 --- a/lib/key-bindings.zsh +++ b/lib/key-bindings.zsh @@ -6,7 +6,6 @@ bindkey -e # Use emacs key bindings bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls -bindkey -s '\e.' '..\n' # [Esc-.] - run command: .. (up directory) bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line. bindkey '^[[5~' up-line-or-history # [PageUp] - Up a line of history bindkey '^[[6~' down-line-or-history # [PageDown] - Down a line of history From ff0cafa14db5b728f823ee486ec1bf5a9d2725eb Mon Sep 17 00:00:00 2001 From: Felix Dreissig Date: Sun, 14 Oct 2012 00:07:47 +0200 Subject: [PATCH 4/5] Make sure the terminal is always in application mode when zle is active. --- lib/key-bindings.zsh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh index 8168c8d90..a57b04122 100644 --- a/lib/key-bindings.zsh +++ b/lib/key-bindings.zsh @@ -2,6 +2,19 @@ # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets +# Make sure that the terminal is in application mode when zle is active, since +# only then values from $terminfo are valid +if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then + function zle-line-init() { + echoti smkx + } + function zle-line-finish() { + echoti rmkx + } + zle -N zle-line-init + zle -N zle-line-finish +fi + bindkey -e # Use emacs key bindings bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark From 174c9177aa34b4c05bb5a1c6f637e6fa479a8e10 Mon Sep 17 00:00:00 2001 From: Felix Dreissig Date: Sun, 14 Oct 2012 02:32:48 +0200 Subject: [PATCH 5/5] Replace hardcoded key escape sequeneces with dynamic ones from terminfo. --- lib/key-bindings.zsh | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh index a57b04122..4a00764da 100644 --- a/lib/key-bindings.zsh +++ b/lib/key-bindings.zsh @@ -20,31 +20,24 @@ bindkey -e # Use emacs key bindings bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line. -bindkey '^[[5~' up-line-or-history # [PageUp] - Up a line of history -bindkey '^[[6~' down-line-or-history # [PageDown] - Down a line of history +bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history +bindkey "${terminfo[knp]}" down-line-or-history # [PageDown] - Down a line of history -bindkey '^[[A' up-line-or-search # start typing + [Up-Arrow] - fuzzy find history forward -bindkey '^[[B' down-line-or-search # start typing + [Down-Arrow] - fuzzy find history backward +bindkey "${terminfo[kcuu1]}" up-line-or-search # start typing + [Up-Arrow] - fuzzy find history forward +bindkey "${terminfo[kcud1]}" down-line-or-search # start typing + [Down-Arrow] - fuzzy find history backward -bindkey '^[[H' beginning-of-line # [Home] - Go to beginning of line -bindkey '^[[1~' beginning-of-line # [Home] - Go to beginning of line -bindkey '^[OH' beginning-of-line # [Home] - Go to beginning of line -bindkey '^[[F' end-of-line # [End] - Go to end of line -bindkey '^[[4~' end-of-line # [End] - Go to end of line -bindkey '^[OF' end-of-line # [End] - Go to end of line +bindkey "${terminfo[khome]}" beginning-of-line # [Home] - Go to beginning of line +bindkey "${terminfo[kend]}" end-of-line # [End] - Go to end of line bindkey ' ' magic-space # [Space] - do history expansion bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word -bindkey '^[[Z' reverse-menu-complete # [TODO] - Perform menu completion, like menu-complete, except that if a menu completion is already in progress, move to the previous completion rather than the next. +bindkey "${terminfo[kcbt]}" reverse-menu-complete # [Shift-Tab] - move through the completion menu backwards -# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~ -bindkey '^?' backward-delete-char # [Delete] - delete backward -bindkey '^[[3~' delete-char # [fn-Delete] - delete forward -bindkey '^[3;5~' delete-char # [TODO] - delete forward -bindkey '\e[3~' delete-char # [TODO] - delete forward +bindkey '^?' backward-delete-char # [Backspace] - delete backward +bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward # consider emacs keybindings: