@@ -44,58 +44,27 @@ Usage
44
44
45
45
1 . Load this script into your interactive ZSH session:
46
46
47
- % source zsh-history-substring-search.zsh
47
+ source zsh-history-substring-search.zsh
48
48
49
49
If you want to use [ zsh-syntax-highlighting] [ 6 ] along with this script,
50
50
then make sure that you load it * before* you load this script:
51
51
52
- % source zsh-syntax-highlighting.zsh
53
- % source zsh-history-substring-search.zsh
52
+ source zsh-syntax-highlighting.zsh
53
+ source zsh-history-substring-search.zsh
54
54
55
- 2 . Bind keyboard shortcuts to this script's functions.
55
+ 2 . Type any part of any previous command and then:
56
56
57
- Users typically bind their UP and DOWN arrow keys to this script, thus:
58
- * 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.)
62
- * Press the UP arrow key and observe what is printed in your terminal.
63
- * 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 ` .
65
- * Use your observations from the previous steps to create key bindings.
66
- For example, if you observed ` ^[[A ` for UP and ` ^[[B ` for DOWN, then:
67
-
68
- bindkey '^[[A' history-substring-search-up
69
- bindkey '^[[B' history-substring-search-down
70
-
71
- However, if the observed values don't work, you can try using terminfo:
72
-
73
- bindkey "$terminfo[kcuu1]" history-substring-search-up
74
- bindkey "$terminfo[kcud1]" history-substring-search-down
75
-
76
- You might also want to bind the Control-P/N keys for use in EMACS mode:
77
-
78
- bindkey -M emacs '^P' history-substring-search-up
79
- bindkey -M emacs '^N' history-substring-search-down
80
-
81
- You might also want to bind the `k` and `j` keys for use in VI mode:
82
-
83
- bindkey -M vicmd 'k' history-substring-search-up
84
- bindkey -M vicmd 'j' history-substring-search-down
85
-
86
- 3 . Type any part of any previous command and then:
87
-
88
- * 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
57
+ * Press the ` history-substring-search-up ` key, which is the UP key by
58
+ default, to select the nearest command that (1) contains your query
90
59
and (2) is also older than the current command in your command history.
91
60
92
- * 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
61
+ * Press the ` history-substring-search-down ` key, which is the DOWN key by
62
+ default , to select the nearest command that (1) contains your query
94
63
and (2) is also newer than the current command in your command history.
95
64
96
65
* Press ` ^U ` the Control and U keys simultaneously to abort the search.
97
66
98
- 4 . If a matching command spans more than one line of text, press the LEFT
67
+ 3 . If a matching command spans more than one line of text, press the LEFT
99
68
arrow key to move the cursor away from the end of the command, and then:
100
69
101
70
* Press the ` history-substring-search-up ` key, which was configured in
@@ -161,6 +130,51 @@ default values.
161
130
receive globally unique search results only once, then use this
162
131
configuration variable, or use ` setopt HIST_IGNORE_ALL_DUPS ` .
163
132
133
+ The following variables must be overridden before having loaded this script
134
+ into your ZSH session, and they define the ` history-substring-search-up ` and
135
+ ` history-substring-search-down ` key bindings.
136
+
137
+ * ` HISTORY_SUBSTRING_SEARCH_MAIN_UP_KEYS ` is a global array that defines the
138
+ main keymap keys to be bind to the ` history-substring-search-up ` command.
139
+ Its default value is ` ('^[[A' $terminfo[kcuu1]) ` , which are two common codes
140
+ for the UP key in most terminals.
141
+
142
+ * ` HISTORY_SUBSTRING_SEARCH_MAIN_DOWN_KEYS ` is a global array that defines the
143
+ main keymap keys to be bind to the ` history-substring-search-down ` command.
144
+ Its default value is ` ('^[[B' $terminfo[kcud1]) ` , which are two common codes
145
+ for the DOWN key in most terminals.
146
+
147
+ * ` HISTORY_SUBSTRING_SEARCH_EMACS_UP_KEYS ` is a global array that defines the
148
+ EMACS mode keys to be bind to the ` history-substring-search-up ` command.
149
+ Its default value is ` ('^P') ` , which is the code for the Control-P key.
150
+
151
+ * ` HISTORY_SUBSTRING_SEARCH_EMACS_DOWN_KEYS ` is a global array that defines the
152
+ EMACS mode keys to be bind to the ` history-substring-search-down ` command.
153
+ Its default value is ` ('^N') ` , which is the code for the Control-N key.
154
+
155
+ * ` HISTORY_SUBSTRING_SEARCH_VICMD_UP_KEYS ` is a global array that defines the
156
+ VI mode keys to be bind to the ` history-substring-search-up ` command.
157
+ Its default value is ` ('k') ` , which is the code for the ` k ` key.
158
+
159
+ * ` HISTORY_SUBSTRING_SEARCH_VICMD_DOWN_KEYS ` is a global array that defines the
160
+ VI mode keys to be bind to the ` history-substring-search-down ` command.
161
+ Its default value is ` ('j') ` , which is the code for the ` j ` key.
162
+
163
+ Users typically bind their UP and DOWN arrow keys to this script. If the
164
+ defaults provided above don't work for you, then:
165
+ * Run ` cat -v ` in your favorite terminal emulator to observe key codes.
166
+ (** NOTE:** In some cases, ` cat -v ` shows the wrong key codes. If the
167
+ key codes shown by ` cat -v ` don't work for you, press ` <Control-v><UP> ` and
168
+ ` <Control-v><DOWN> ` at your ZSH command line prompt for correct key codes.)
169
+ * Press the UP arrow key and observe what is printed in your terminal.
170
+ * Press the DOWN arrow key and observe what is printed in your terminal.
171
+ * Press the Control and C keys simultaneously to terminate the ` cat -v ` .
172
+ * Use your observations from the previous steps to create key bindings.
173
+ For example, if you observed ` ^[OA ` for UP and ` ^[OB ` for DOWN, then:
174
+
175
+ HISTORY_SUBSTRING_SEARCH_MAIN_UP_KEYS=('^[OA')
176
+ HISTORY_SUBSTRING_SEARCH_MAIN_DOWN_KEYS=('^[OB')
177
+ source zsh-history-substring-search.zsh
164
178
165
179
History
166
180
------------------------------------------------------------------------------
0 commit comments