ohmyzsh: vi-mode plugin must be loaded first or it wipes out custom keybindings in other plugins
It would appear that if the vi-mode plugin appears in the list of plugins after another plugin which defines a keybinding using bindkey, that keybinding is removed. Specifically, the keybindings I’ve observed this with are:
bindkey "^[[1;6D" insert-cycledleft
bindkey "^[[1;6C" insert-cycledright
(from https://github.com/mcornella/oh-my-zsh/commit/383ae2d4aa1c4fa90bf35cdd6e13598dacafa5b1).
This isn’t documented anywhere (I believe), and isn’t obvious. Perhaps there’s a way to always logically sort vi-mode to the head of the list of plugins, irrespective of where it’s defined? Or emit a warning if it isn’t first?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 1
- Comments: 20 (15 by maintainers)
A “keymap” is a named set of key bindings.
zshmaintains a few of them to switch between, depending on what you’re doing.I don’t think there’s an easy fix for this, because
vi-modeand the other key binding stuff in OMZ grew kind of organically. Best you can do in the short term is have plugins that know they don’t want to be clobbered byvi-modecheck the$pluginslist to see ifvi-modeis being loaded after them. We could supply a function inlibthat made that easy for the plugins to do. (And it could be added to later if other plugins were created that switched or clobbered the keymap likevi-modedid and needed to be checked similarly.)Some other plugins add key bindings; they’d probably want to check for it, too.
Alternately, we could just put the check in
vi-modeitself, and have it check for a list of plugins known to add key bindings, and issue a single warning.Part of the issue may be that the
bindkey -eandbindkey -vcommands thatlib/key-bindings.zshand thevi-modeplugin use don’t just set up key bindings. They set up links between keymaps and change which one is linked tomainand thus the default.From the ZLE Builtins section of the manual:
This means that
libfiles, user custom files, and plugins loaded beforevi-modeare modifying theemacskeymap, and plugins loaded aftervi-mode(and the rest of your.zshrc) are modifying theviinskeymap, which is now the default. You can observe this by looking atbindkey -lLAnd then you have to consider the specific key bindings that
vi-modemakes inside theviinskeymap.If you want all the various files that set key bindings to play nicer with each other, you might add a
$ZSH_INITIAL_KEYMAPoption to let the user select whetherbindkey -eorbindkey -vis done initially inlib/key-bindings.sh. But that begs the question of whether those various files would work well with theviinskeymap, or if they’re just made to work with the current behavior of always starting with theemacskeymap. And it would impair the ability of the user to switch between the two at runtime. (Not a common case, surely, but it’s something that’s at least not actively interfered with now.) Most of the existing bindings look emacs-y.