I wanted to override the keybinding for Ctrl-Alt-P in my user keymap. It seemed straightforward enough, but it didn’t seem to be working.
I’ll walk you through my debugging step-by-step so you can point out if I did anything dumb along the way – note that all of the following was done in safe mode with my previous keymap commented out to try and prevent polluting the environment.
I first sanity check that the default command runs before I modify anything:
Good start. I add my modified keybinding:
Wonderful. Unlike my actual keymap, the override worked. So I probe further…:
The second keybinding overrode the first as expected. This is all going too well. So I try a different key combination on the same selector:
… Huh. I had assumed that the different key combinations would be merged, but instead the newest selector has completely overwritten the first two, restoring the default command.
Sure enough, if I consolidate all of my overrides and de-dupe the selectors, everything works as expected.
I’m running Atom 1.6.0-beta8 on Windows 10 x64. I’ve also had problems performing the same overrides with the same Atom version on Linux (although I have not performed the same detailed investigation I have here to verify the issue is identical).
Is the above behaviour intended?
I read through the in-depth keymaps docs but must admit I didn’t see any warning to not have multiple identical selectors. The fact that the
key snippet, recommended in the default user keymap’s header itself, also creates a selector makes it seem like this isn’t intended.
The reason I had multiple identical selectors in the first place is because I like to separate the overrides in my keymap by purpose. Sometimes that purpose - be it project switching, package development, opening files as a few examples – involves overriding keybindings at multiple selectors, and I like to keep those together.