From 2f8a21062c0df0d5c6be8f0726655fd6e9fbd71c Mon Sep 17 00:00:00 2001 From: "Suraj N. Kurapati" Date: Wed, 19 Oct 2016 14:25:44 -0700 Subject: [PATCH] README: bind arrow keys after observing key codes Don't suggest using $terminfo[kcuu1] or $terminfo[cuu1] lookups anymore! Instead, have the user observe the actual key codes for their arrow keys using `cat -v` and then use those observed values to create keybindings. This should eliminate confusion and complaints about binding arrow keys. See https://github.com/zsh-users/zsh-history-substring-search/issues/63 --- README.md | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e29fa3b..f1bb798 100644 --- a/README.md +++ b/README.md @@ -32,30 +32,25 @@ Usage % source zsh-syntax-highlighting.zsh % source zsh-history-substring-search.zsh -2. Bind keyboard shortcuts to this script's functions: +2. Bind keyboard shortcuts to this script's functions. - ## Arrow Keys ########################################### + Arrow keys: + * Run `cat -v` in your favorite terminal emulator to observe key codes. + * Press the UP arrow key and observe what is printed in your terminal. + * Press the DOWN arrow key and observe what is printed in your terminal. + * Press the Control and C keys simultaneously to terminate the `cat -v`. + * Use your observations from the previous steps to create key bindings. + For example, if you observed `^[[A` for UP and `^[[B` for DOWN, then: - # OPTION 1: for most systems - zmodload zsh/terminfo - bindkey "$terminfo[kcuu1]" history-substring-search-up - bindkey "$terminfo[kcud1]" history-substring-search-down + bindkey '^[[A' history-substring-search-up + bindkey '^[[B' history-substring-search-down - # OPTION 2: for iTerm2 running on Apple MacBook laptops - zmodload zsh/terminfo - bindkey "$terminfo[cuu1]" history-substring-search-up - bindkey "$terminfo[cud1]" history-substring-search-down - - # OPTION 3: for Ubuntu 12.04, Fedora 21, and MacOSX 10.9 - bindkey '^[[A' history-substring-search-up - bindkey '^[[B' history-substring-search-down - - ## EMACS mode ########################################### + You might also want to bind the Control-P/N keys for use in EMACS mode: bindkey -M emacs '^P' history-substring-search-up bindkey -M emacs '^N' history-substring-search-down - ## VI mode ############################################## + You might also want to bind the `k` and `j` keys for use in VI mode: bindkey -M vicmd 'k' history-substring-search-up bindkey -M vicmd 'j' history-substring-search-down