Use same keybinding as command (and override it)?


Is it possible to explicitly use the same keybinding as a certain command, in order to override it no matter what its keybinding is? For example, say you had a command you wanted to override find-and-replace:show:

  'cmd-f': 'find-and-replace:show'
  'cmd-f': 'my-package:show'

Is it possible to specify "the same keybinding as find-and-replace-show" instead of writing the keybinding itself (which could change)? Something like:

  'cmd-f': 'find-and-replace:show'
  'find-and-replace:show': 'my-package:show'



No, not the way the system is currently designed.


You can use KeymapManager::findKeyBindings to find out the key-combo bound to a command. Then use that information to write to a keymap file that you are watching with KeymapManager::watchKeymap.

You can also overwrite the find-and-replace:show command:

atom.commands.add 'find-and-replace:show', ->
  // code you want to run on 'find-and-replace:show'

This way it can be a bit tricky which package’s command runs first