How to turn on / change language syntax highlighting


Working on a html.twig file (have seen this happen in other files too) and Atom isn’t highlighting any of the language syntax, is there a way to force a specific language to be used i.e. PHP or html etc…?


To temporarily change the grammar, hit ctrl-shift-L and select the grammar you’d like to use.

To permanently change the grammar for a certain file extension, add the following to your init script (

path = require 'path'

atom.workspaceView.eachEditorView (editorView) ->
  editor = editorView.getEditor()
  if path.extname(editor.getPath()) is '.twig'
    grammars = atom.syntax.getGrammars().filter (grammar) -> is 'HTML'
    editor.setGrammar grammars[0]

I suspect there is an easier way to accomplish this but I couldn’t find a simple way to get a hold of the html grammar object.

To find the correct grammar name look at the result of console.table(atom.syntax.getGrammars(), 'name') in the console.


There’s also the file-types package that basically does this already.



grammar = atom.grammars.grammarForScopeName 'scope.html'
editor.setGrammar grammar


There is a FAQ for this now:

The solution is much simpler and more comprehensive.