@@ -42,72 +42,77 @@ Using [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh):
42
42
Usage
43
43
------------------------------------------------------------------------------
44
44
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.
46
48
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:
58
51
* 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.)
62
56
* Press the UP arrow key and observe what is printed in your terminal.
63
57
* 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 ` .
65
59
* Use your observations from the previous steps to create key bindings.
66
60
For example, if you observed ` ^[[A ` for UP and ` ^[[B ` for DOWN, then:
67
61
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')
70
64
71
65
However, if the observed values don't work, you can try using terminfo:
72
66
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])
75
69
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:
77
72
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')
80
75
81
76
You might also want to bind the ` k ` and ` j ` keys for use in VI mode:
82
77
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
85
90
86
91
3 . Type any part of any previous command and then:
87
92
88
93
* 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
90
95
and (2) is also older than the current command in your command history.
91
96
92
97
* 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
94
99
and (2) is also newer than the current command in your command history.
95
100
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.
97
102
98
103
4 . If a matching command spans more than one line of text, press the LEFT
99
104
arrow key to move the cursor away from the end of the command, and then:
100
105
101
106
* 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.
103
108
When the cursor reaches the first line of the command, pressing the
104
109
` history-substring-search-up ` key again will cause this script to
105
110
perform another search.
106
111
107
112
* 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.
109
114
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
111
116
above, again will cause this script to perform another search.
112
117
113
118
@@ -161,6 +166,27 @@ default values.
161
166
receive globally unique search results only once, then use this
162
167
configuration variable, or use ` setopt HIST_IGNORE_ALL_DUPS ` .
163
168
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.
164
190
165
191
History
166
192
------------------------------------------------------------------------------
0 commit comments