How do I make a default syntax by filetype in Atom text editor?

前端 未结 7 583
暗喜
暗喜 2021-01-31 02:17

I want my .ejs files to have html syntax, however, it always opens the files as Plain Text.

In sublime you can choose \"Open all with current extension as...\" then ch

相关标签:
7条回答
  • 2021-01-31 02:25

    It looks likes there's a brand new package has been released for this. https://atom.io/packages/language-ejs.

    0 讨论(0)
  • 2021-01-31 02:26

    This is now in Atom core, you don't need that file-types package any more.

    Where I work, we use .phl for a certain kind of PHP file. To tell Atom about this, edit config.cson like so:

    core:
        customFileTypes:
          "text.html.php": [
            "phl"
          ]
        themes: [
    // snip
    

    You can find this file at ~/.atom/config.cson, or from the Settings window click the "Open Config Folder" button.

    It's easy to get wrong, as evidenced by the many errors people made on the GitHub issue for the feature.

    0 讨论(0)
  • 2021-01-31 02:33

    As Dave Andersen mentions in a buried comment, it is now possible to do this without any extra packages and it's documented here.

    0 讨论(0)
  • 2021-01-31 02:35

    Edit: since the time I wrote this answer, this functionality has been added to Atom core, see this answer for details.

    file-types Atom package

    (https://atom.io/packages/file-types)

    It does exactly what the title question asks for: you can define new file extensions for existing languages with a simple edit of the config.cson file.

    0 讨论(0)
  • 2021-01-31 02:37

    For example if you want to open all .jsx files with javascript syntax, you need to add this to your config.cson

    "*":
      core:
        customFileTypes:
          "source.js": [
             "jsx"
          ]
    

    This maps all .jsx files to open with js syntax.

    0 讨论(0)
  • 2021-01-31 02:41

    For individual files you can use the Grammar Selector; Ctrl+Shift+L to set which language you're using on that file. Not the same as auto-detect but useful for those times when you're using a file that you don't want to set a default for.

    0 讨论(0)
提交回复
热议问题