Using the same keymap, but in different files?


Is it possible to do something like this in my keymap.cson:

  '.platform-darwin atom-workspace atom-text-editor':
    'cmd-e': 'atom-autocomplete-php:goto'

  '.platform-darwin atom-workspace atom-text-editor':
    'cmd-e': 'tern:definition'

I would like to use the same key binding for both. Is it possible to do something like this?


Yes, to my knowledge it is possible. I don’t remember the exact syntax, but you can use the language as part of the selector, not as a separate level like you show. See this discussion here for more information and links:

Also, it looks like you’re essentially wanting different autocomplete engines based on the language. That’s already possible and built-in to autocomplete-plus. Just install the autocomplete engines you want for various languages or other uses and things just work.


Couldn’t find what I needed in your links.
The 2 packages in the snippet I showed is not like autocomplete-plus, they’re used to go to the declaration of a give class or function/method.

Also tried it like this, but no luck…

'.platform-darwin atom-workspace atom-text-editor[data-grammar="text php"]':
  'cmd-e': 'atom-autocomplete-php:goto'

'.platform-darwin atom-workspace atom-text-editor[data-grammar="text js"]':
  'cmd-e': 'tern:definition'

If you can remember what the syntax was that’d be great :slightly_smiling:


I think the new selectors you posted are close. I would leave out the text part though. In the JS case because there isn’t a text.js scope, it is source.js … and in the other because you’re exactly matching, so order would matter. I would use data-grammar$='php' and data-grammar$='js'.

As far as going to a declaration … there is the built-in symbols-view package which does what you want, so long as you provide a ctags-compliant tags file.


I got it working, thanks @leedohm !

Anyone that is interested in how it is done, or you want to do something similar here is how I got it to work:

'.platform-darwin atom-workspace atom-text-editor[data-grammar$="php"]':
  'cmd-e': 'atom-autocomplete-php:goto'

'.platform-darwin atom-workspace atom-text-editor[data-grammar$="js"]':
  'cmd-e': 'tern:definition'