Keybindings for Grammar Rules


I’d like to make keybindings specific to scopes I’ve specified in my grammar file, for example:

  'enter': 'organized:newTableRow'


  'enter': 'organized:newStarLine'

But so far I can’t seem to get that to work. The canonical ‘atom-text-editor[data-grammar=“source organized”]’ selector works, but only allows me to bind a keystroke to my entire package.

I’ve tried a wide variety of selectors, such as:

  • ‘atom-text-editor[data-grammar=“source organized”] span.border.table.organized’
  • ‘span.border.table.organized’
  • ‘.border.table.organized’

In all cases, the keybinding resolver shows my keybinding grayed out with an X next to it, despite the fact that the editor:log-cursor-scope command will show "border.table.organized’ as being an active scope.

Any thoughts? Perhaps the keymappings just don’t support scopes at this point?


There isn’t a way to bind a keybinding to specific scopes within an editor. The best you can do is to bind keybindings to the editor itself. From there, you can have logic in your command that determines if the cursor or cursors are at the proper locations for your command to execute or bail if they aren’t.


Thanks Lee, that’s what I was starting to expect. I’ll put a pull request in for the docs to see if I can make that part a bit more clear.