How can I make all new files open with a specific grammar or syntax?


Newly created files in Atom are always “Plain Text”. Let’s say I want to change this so that new files will automatically be in another language, for example “Shell Script (Bash)”.

The following code, added to your, will do this:

atom.workspace.observeTextEditors (editor) ->
  original = editor.getGrammar()
  if original? and original is atom.grammars.grammarForScopeName('text.plain.null-grammar')

Things to note:

  • The file is where you can customize Atom without having to write a package
  • The observeTextEditors method sets a callback that is called upon each TextEditor creation for currently open and future editors
  • The code above:
    1. Checks the grammar that the editor was created with
    2. If and only if it is the default (“null”) grammar, it sets the editor’s grammar to the Shell grammar

Change Default Syntax for All New Unsaved Documents
Default format when opening a new file
Saving file with right filetype
Call function from different file? Also, creating new file does not have any language on it
(VHDL) Extract line comments marked by '--' to create a Markdown document
A couple of questions for Atom