Change Default Syntax for All New Unsaved Documents


I’ve searched extensively and found many articles that sound similar but are subtly different from what I’m looking for.

When opening a file such as index.html atom automatically knows to style the syntax properly, great. Or if I create a document and save it as say test.html it automatically knows to change the syntax to be HTML, great. However, the following is my issue…

Often I paste in code into Atom to quickly edit something and then copy and paste that code back somewhere else. For instance editing code from MailChimp or countless other places. The problem is when you open up atom it defaults to “Plain Text” and if you never actually save the file it will never change from Plain Text and instead each time you have to manually click Plain Text at the bottom and select the language of choice to get proper syntax highlighting.

What I would like to do is change the default Plain Text to say HTML or PHP. And of course if when I save the article as .js or something then like normal it would update to javascript syntax. Does anyone know how to change the default syntax from Plain Text to PHP either via ideally the native config file or if not available via a plugin? Or if you are aware of any help document that outlines this already would be grateful if you could point me to it. Thank you!


We have a FAQ on this here:


Thanks, you rock!



Just tried this out but can’t seem to get it to work. Tried to reply to that message you linked to but doesn’t seem to allow comments so will post here.

Opened ~/.atom/ and pasted in your above code. I changed, “” to “source.php” so the new default for all documents would be PHP syntax. I saved the coffee file and restarted atom. Opened a new blank document and it still appears to be defaulting to Plain Text syntax. Am I missing something?


I belive the grammar name is text.html.php for php files and not source.php. I got this information by running atom.grammars.selectGrammar('x.php').scopeName in the console.

Here is what I added to my before restarting Atom to test. Opening a new untitled document changed the syntax in the bottom right corner to PHP.

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


Thanks, that makes sense and glad it’s working on your end, that’s promising. However when copying and pasting that into the file, saving the file, then restarting Atom. And opening a new blank file it still defaults to Plain Text.

Checked and I’m using the latest stable version.

Are you are aware of anything else I might need to do, to get the to take affect? Such as restarting the whole computer or emptying some sort of cache in Atom? Any changes made to my preference files always take affect right away but haven’t have tried the file before.


Restarting Atom is the only thing you need to do in order to make the take effect. Keep in mind that CoffeeScript is an indentation-sensitive language. If you change the indentation, you can change the meaning of the code and it may not work.


Thanks for the screenshots it helped clarify what might be happening.

If I open Atom the editor that opens by the Open Empty Editor At Start config seems to be Plain Text syntax. Other editors opened with Ctrl+N use the PHP syntax. Is this maybe what is happening to you? Did you open that empty editor or was it opened automatically when you started Atom?


When opening Atom for the first time, such as clicking in the dock, or via Spotlight or Alfred, the default blank window opens Plain Text. If I then click open new window it also defaults to Plain Text. However, I can confirm now, that if in one of those windows I choose File > New Tab or Ctrl+N it does default to PHP.

So looks like the issue is that it is not defaulting new windows or the intial window to the desired syntax. Not sure if anyone is aware of any code to resolve this issue, or a package, or if something that will need to be resolved/changed in the Atom Core update in the future to make it possible? Thanks!


Used the indentation provided by you and others (just copied and pasted) but it looks like Ben3eeE is able to replicate that it only works when doing a new tab and not the default window or new window as desired.


I suspect that the initial file is opened before gets a chance to run.


Yeah so sounds like the solution posted here, and on GitHub and on the Atom FAQ won’t work. Hopefully someone here or on GitHub will have another potential solution on how to resolve it via a preference setting, or a plugin, or if neither are possible open an an issue with developers to have that updated in a future Atom release.


It will work. You’ll probably just have to change the conditional to ask if getTitle() is untitled.


Thanks @Damned. Could you provide suggested sample code on how that would work?

Currently trying the official version on the Atom Forum FAQ as well as the ones suggested in this thread such as:

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

Something like this?..

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

Will try that and a few variations when I’m back at my desk and not on my phone, or if you or anyone has recommendation, that would be great. Thanks so much.


It would look like this:

atom.workspace.observeTextEditors (editor) ->
  if editor.getTitle() is "untitled"

But I tried it and it’s the same problem. observeTextEditors should catch all currently open editors on its first run and then all new editors, but no dice.


Yeah, this sounds like a bug to me. I would expect it to work on the first editor.


Thanks both. Not sure if one of you knows the best way to report the bug and include the relevant technical info, if you’d suggest I create a GitHub issue including your comments. Thanks either way everyone.


When you create an issue on atom/atom you will get a default issue template, fill out that template completely and include a link to this discussion. Also be sure to read the reporting bugs section of the documentation which has a slightly different template that you can follow or take inspiration from.

Don’t forget to mention that having the Open Empty Editor On Start option enabled is required as this issue only occurs on the first editor created by that option. Also include the full coffeescript snippet that you used.

If you are unsure that creating an issue is a good option from here and that this seems like a valid bug or something we can always wait for @leedohm to reply with his thoughts.


On the more practical side, until the apparent bug is fixed, you have two options. The first is to unset Open Empty Editor on Start, include the code, and then just open a new file when you start Atom. The second would be to set up a keybinding that switches the grammar to a language you use all the time. Each of these solutions requires one extra key press on your part, and with the second way, you only have to use the command when you’re working on code that’s long enough for you to want highlighting.


You should follow @Ben3eeE’s great suggestions and when you file the Issue, please post a link to the Issue here in this topic for others to find more easily :grinning: