Reputation: 2876
I'm starting to use zsh on macOS Sierra. I would like to have the following key mappings:
However, I can't seem to differentiate between the two. I'm only able to get Enter, and Esc-Enter, but not Shift-Enter:
bindkey "^M" accept-line # Enter
bindkey "^[^M" accept-and-hold # Esc-Enter
bindkey "????" accept-and-hold # Shift-Enter
Is it possible to detect and handle Shift-Enter?
Upvotes: 14
Views: 8159
Reputation: 18429
zsh
(as well as other shells) do not act on key bindings but rather on key sequences received from the terminal. Converting key presses and combinations into key sequences is the responsibility of the terminal. You can retrieve the key sequence for a key combination by pressing Ctr+v followed by the key combination, e.g. Shift+Enter.
By default Enter and Shift+Enter (as well as Ctrl+v and Ctrl+Shift+m) all generate the identical key sequence ^M
(at least in most common terminal emulators).
Fortunately, some terminal emulators allow to configure the key sequences sent. For example iTerm2 allows you to set customized key bindings that send escape sequences (in Profile > Keys), you should be able to define a sequence for Shift+Enter there, e.g. [[SE
and can then make the appropriate settings in zsh
: bindkey '^[[[SE' 'accept-and-hold'
. (Unfortunately I do not have access to a Mac at the moment, so I could not test this).
Upvotes: 16
Reputation: 90
This might answer your problem (can't put it into comment, don't have 50 rep). You might try # showkey --scancodes
which gives you key codes and take a look into the manual-pages e.g. man zshzle
and search for "code". I have tried to map the shift key without success. Might be it's not possible. Also have a look into bindkey -l
wich gives you the keymaps and bindkey -M emacs
for emacs keymap
Upvotes: 0