[SOLVED] How: Exclude keybinding for language grammar


Hi there.

According to the Flight Manual a keybinding can be associated with a grammar (read: ‘language’).

Please help me - how to identify the scope of a keybinding to exclude a grammar?

My objective is a solution for: (gfm = Github Version MarkDown)

'atom-text-editor:not([mini]) , not(source.gfm)':
# should exclude all non-program languages
  'alt': 'placeRuler'
  '^alt': 'hideRuler'

Thanks for your attention.


Extending my question (please)…
Is it possible declare a variable inside the keymap.cson code?

allTextFiles := source.gfm & text.plain


The keys in keymap.cson are CSS selectors. Here’s a good guide for using the :not() feature. It should be .source.gfm, because those are two class names.


Hello. I have digged into the resource you linked to - thank you.

I have come up with the following:

"atom-text-editor:not(.mini):not([data-grammar='text plain']):not([data-grammar='source gfm'])":
  'alt': 'placeRuler'
  '^alt': 'hideRuler'


  1. Positions of the " and ' quotes.
  2. The . in .mini … (child?)
  3. The [ ] in the attribute
  4. The 'source gfm' without the .

Is there a way:
a) Combining the attribute tests as [data-grammar='text plain' | 'source gfm']
…(above does not work)
b) Combining the not() to not(.mini [data-grammar='text plain' | 'source gfm']
…(above does not work)
c) Making a constant / variable to represent 'text plain' or 'source gfm'
d) Write the scope over multiple lines…(below does not work)

  not([data-grammar='text plain']):/ 
  not([data-grammar='source gfm'])":
    'alt': 'placeRuler'
    '^alt': 'hideRuler'

Thanks again for the chat.


…variation to working code -
     Note the ~=

"atom-text-editor:not(.mini):not([data-grammar~='text']):not([data-grammar='source gfm'])":
  'alt': 'placeRuler'
  '^alt': 'hideRuler'


You removed the [] from [mini], which was the thing you had right. This works for me:

"atom-text-editor:not([mini]):not([data-grammar='text plain']):not([data-grammar='source gfm'])"


:slightly_smiling_face: The not(.mini) seems to work too.


Ah, fair. I just checked and there it is. Not sure why it needs both a .mini class and a mini attribute.


What I can tell you is that not(.data-grammar='text plain') does not work.

I assume that you can reach mini by atom-text-editor.mini which is an (?) object and a (?) child of atom-text-editor. But it is also captured as an attribute. [1]

atom-text-editor.data-grammar() is however an attribute of atom-text-editor and not a (?) child.

I am inclined to think that the functionality of [1] is unintended. The [xx] should not work.

Mr. Wilson - Do you still wear your ‘academic’ hat? Am my assumptions good or how am I wrong?


You’re wrong because this is how a mini editor is defined (taken from the find-and-replace feature):

The mini attribute (which the cursor is pointing at) is the thing being checked by atom-text-editor[mini] or atom-text-editor:not([mini]). I was wrong because I forgot that it also had a .mini class.


:smile: { Thank you! }