@@ -42,72 +42,77 @@ Using [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh):
4242Usage
4343------------------------------------------------------------------------------
4444
45- 1 . Load this script into your interactive ZSH session:
45+ 1 . Define the keys to be bind to the ` history-substring-search-up ` and
46+ ` history-substring-search-down ` functions from this script. This can be
47+ done using the variables shown below.
4648
47- % source zsh-history-substring-search.zsh
48-
49- If you want to use [ zsh-syntax-highlighting] [ 6 ] along with this script,
50- then make sure that you load it * before* you load this script:
51-
52- % source zsh-syntax-highlighting.zsh
53- % source zsh-history-substring-search.zsh
54-
55- 2 . Bind keyboard shortcuts to this script's functions.
56-
57- Users typically bind their UP and DOWN arrow keys to this script, thus:
49+ Users typically bind their UP and DOWN arrow keys to these functions,
50+ thus:
5851 * Run ` cat -v ` in your favorite terminal emulator to observe key codes.
59- (** NOTE:** In some cases, ` cat -v ` shows the wrong key codes. If the
60- key codes shown by ` cat -v ` don't work for you, press ` <C-v><UP> ` and
61- ` <C-v><DOWN> ` at your ZSH command line prompt for correct key codes.)
52+ (** NOTE:** In some cases, ` cat -v ` shows the wrong key codes. If the
53+ key codes shown by ` cat -v ` don't work for you, press ` <CONTROL-v><UP> `
54+ and ` <CONTROL-v><DOWN> ` at your ZSH command line prompt for correct key
55+ codes.)
6256 * Press the UP arrow key and observe what is printed in your terminal.
6357 * Press the DOWN arrow key and observe what is printed in your terminal.
64- * Press the Control and C keys simultaneously to terminate the ` cat -v ` .
58+ * Press the CONTROL and C keys simultaneously to terminate the ` cat -v ` .
6559 * Use your observations from the previous steps to create key bindings.
6660 For example, if you observed ` ^[[A ` for UP and ` ^[[B ` for DOWN, then:
6761
68- bindkey '^[[A' history-substring-search-up
69- bindkey '^[[B' history-substring-search-down
62+ HISTORY_SUBSTRING_SEARCH_UP_MAIN_KEYS=( '^[[A')
63+ HISTORY_SUBSTRING_SEARCH_DOWN_MAIN_KEYS=( '^[[B')
7064
7165 However, if the observed values don't work, you can try using terminfo:
7266
73- bindkey " $terminfo[kcuu1]" history-substring-search-up
74- bindkey " $terminfo[kcud1]" history-substring-search-down
67+ HISTORY_SUBSTRING_SEARCH_UP_MAIN_KEYS=( $terminfo[kcuu1])
68+ HISTORY_SUBSTRING_SEARCH_DOWN_MAIN_KEYS=( $terminfo[kcud1])
7569
76- You might also want to bind the Control-P/N keys for use in EMACS mode:
70+ You might also want to bind the CONTROL-P and CONTROL-N keys for use in
71+ EMACS mode:
7772
78- bindkey -M emacs '^P' history-substring-search-up
79- bindkey -M emacs '^N' history-substring-search-down
73+ HISTORY_SUBSTRING_SEARCH_UP_EMACS_KEYS=( '^P')
74+ HISTORY_SUBSTRING_SEARCH_DOWN_EMACS_KEYS=( '^N')
8075
8176 You might also want to bind the ` k ` and ` j ` keys for use in VI mode:
8277
83- bindkey -M vicmd 'k' history-substring-search-up
84- bindkey -M vicmd 'j' history-substring-search-down
78+ HISTORY_SUBSTRING_SEARCH_UP_VICMD_KEYS=('k')
79+ HISTORY_SUBSTRING_SEARCH_DOWN_VICMD_KEYS=('j')
80+
81+ 2 . Load this script into your interactive ZSH session:
82+
83+ source zsh-history-substring-search.zsh
84+
85+ If you want to use [ zsh-syntax-highlighting] [ 6 ] along with this script,
86+ then make sure that you load it * before* you load this script:
87+
88+ source zsh-syntax-highlighting.zsh
89+ source zsh-history-substring-search.zsh
8590
86913 . Type any part of any previous command and then:
8792
8893 * Press the ` history-substring-search-up ` key, which was configured in
89- step 2 above, to select the nearest command that (1) contains your query
94+ step 1 above, to select the nearest command that (1) contains your query
9095 and (2) is also older than the current command in your command history.
9196
9297 * Press the ` history-substring-search-down ` key, which was configured in
93- step 2 above, to select the nearest command that (1) contains your query
98+ step 1 above, to select the nearest command that (1) contains your query
9499 and (2) is also newer than the current command in your command history.
95100
96- * Press ` ^U ` the Control and U keys simultaneously to abort the search.
101+ * Press the CONTROL and U keys simultaneously to abort the search.
97102
981034 . If a matching command spans more than one line of text, press the LEFT
99104 arrow key to move the cursor away from the end of the command, and then:
100105
101106 * Press the ` history-substring-search-up ` key, which was configured in
102- step 2 above, to move the cursor to the line above the cursored line.
107+ step 1 above, to move the cursor to the line above the cursored line.
103108 When the cursor reaches the first line of the command, pressing the
104109 ` history-substring-search-up ` key again will cause this script to
105110 perform another search.
106111
107112 * Press the ` history-substring-search-down ` key, which was configured in
108- step 2 above, to move the cursor to the line below the cursored line.
113+ step 1 above, to move the cursor to the line below the cursored line.
109114 When the cursor reaches the last line of the command, pressing the
110- ` history-substring-search-down ` key, which was configured in step 2
115+ ` history-substring-search-down ` key, which was configured in step 1
111116 above, again will cause this script to perform another search.
112117
113118
@@ -161,6 +166,27 @@ default values.
161166 receive globally unique search results only once, then use this
162167 configuration variable, or use ` setopt HIST_IGNORE_ALL_DUPS ` .
163168
169+ The following variables can be set before having loaded this script into your
170+ ZSH session to define the ` history-substring-search-up ` and
171+ ` history-substring-search-down ` key bindings.
172+
173+ * ` HISTORY_SUBSTRING_SEARCH_UP_MAIN_KEYS ` is a global array that defines the
174+ main keymap keys to be bind to the ` history-substring-search-up ` function.
175+
176+ * ` HISTORY_SUBSTRING_SEARCH_DOWN_MAIN_KEYS ` is a global array that defines the
177+ main keymap keys to be bind to the ` history-substring-search-down ` function.
178+
179+ * ` HISTORY_SUBSTRING_SEARCH_UP_EMACS_KEYS ` is a global array that defines the
180+ EMACS mode keys to be bind to the ` history-substring-search-up ` function.
181+
182+ * ` HISTORY_SUBSTRING_SEARCH_DOWN_EMACS_KEYS ` is a global array that defines the
183+ EMACS mode keys to be bind to the ` history-substring-search-down ` function.
184+
185+ * ` HISTORY_SUBSTRING_SEARCH_UP_VICMD_KEYS ` is a global array that defines the
186+ VI mode keys to be bind to the ` history-substring-search-up ` function.
187+
188+ * ` HISTORY_SUBSTRING_SEARCH_DOWN_VICMD_KEYS ` is a global array that defines the
189+ VI mode keys to be bind to the ` history-substring-search-down ` function.
164190
165191History
166192------------------------------------------------------------------------------
0 commit comments