1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-22 08:08:00 +00:00

[editor] Fix undefined results with unbound keys in viins/vicmd

Bind the remaining unbound keys in the main mode so that they
don't result in undefined functionality when pressed. (Often this
will change the casing of one/most/all of the characters you've
typed or even stranger things). In emacs mode this usually just
inserts a tilde, but this will fix that as well so nothing happens
when unbound keys are pressed.

Since there isn't any binding which does "nothing", create a noop
ZLE widget and bind them to that.

The user or other modules are still able to override these bindings
either by overriding the main keymap or setting a keymap in one
of the other modes which will take precedence over the main fallback.
This commit is contained in:
Samantha McVey 2017-07-07 12:50:53 -07:00 committed by Kaleb Elwert
parent db48a22c74
commit e3520b737f

View File

@ -282,6 +282,32 @@ fi
# Emacs and Vi Key Bindings
#
# Unbound keys in vicmd and viins mode will cause really odd things to happen
# such as the casing of all the characters you have typed changing or other
# undefined things. In emacs mode they just insert a tilde, but bind these keys
# in the main keymap to a noop op so if there is no keybind in the users mode
# it will fall back and do nothing.
function _prezto-zle-noop { ; }
zle -N _prezto-zle-noop
local unbound_keys=(
"${key_info[F1]}"
"${key_info[F2]}"
"${key_info[F3]}"
"${key_info[F4]}"
"${key_info[F5]}"
"${key_info[F6]}"
"${key_info[F7]}"
"${key_info[F8]}"
"${key_info[F9]}"
"${key_info[F10]}"
"${key_info[F11]}"
"${key_info[F12]}"
"${key_info[PageUp]}"
"${key_info[PageDown]}"
)
for keymap in $unbound_keys; do
bindkey -M main "${keymap}" _prezto-zle-noop
done
# Ctrl + Left and Ctrl + Right bindings to forward/backward word
for keymap in viins vicmd; do
for key in "${(s: :)key_info[ControlLeft]}"