Custom file types in IntelliJ IDEA

IntelliJ IDEA is a great IDE for Java, Groovy, Flex, Python, Ruby and many other languages. The text editor with camel-hump completion, and version control support are so great that it may be hard to switch to another editor which may lack some useful features. So, when a need arises for me to code in a language that’s not listed on the features page, I just teach IDEA some basics about that language, and feel much more comfortable than I would if I was editing a plain text. Luckily, you don’t have to write a plugin for that, it is possible via the GUI.

Assume you want to edit Haskell code in IDEA. You go to IDE Settings | File Types and press the ‘Add‘ button next to the file types list:

This brings a dialog where you can provide some knowledge about Haskell: case sensitivity, brace matching settings, ways of defining comments and keywords. You can have up to four lists of keywords, which will be colored differently in the editor. And, of course, all of them will be auto-completed.

After you are done with this dialog, all that remains is to assign the *.hs extension to the newly created file type:

And enjoy hacking:

This entry was posted in Tips & Tricks and tagged , , . Bookmark the permalink.

19 Responses to Custom file types in IntelliJ IDEA

  1. Leonidos says:

    Very stricted options. What about hex numvers like 0ABCh (like in asm)?
    What if sets of reserved words depend on context?
    Why not to provide regular expression like syntax for comments, numbers, reserved words, etc?

  2. Slawek Zachcial says:

    Hi JetBrains,

    I love Intellij and that’s the IDE that I use for all the programming work I do.

    Sometimes I need to edit files that are not part of any project – just one-off edit tasks. I’d be so cool to do this in Idea because of its fantastic editing capabilities. But starting IDE for such a small thing is an overkill.

    I’m thinking there would be a market share to capture if you provided a quick startup and memory efficient editor to handle such edits which do not require a full-blown IDE (with project mgmt and all other goodies). It could replace notepads, textpads, ultraedits, E, etc… I believe all the components are already there. It’s probably just a matter of bundling them together in a scaled-down version.

    Just a thought…

    Keep rocking!
    /Slawek

  3. Hans says:

    I have to agree with Leonidos. Not much to brag about here ;-) Very very limited capabilities, only works for the most simple of syntaxes. Try using this to highlight markup, ini-files, yaml (I know it’s build in), .htacces, embedded regex, etc, etc. Not a very useful feature in its present incarnation. Why not develop some kind of dsl to do the highlighting? Perhaps something like what vim has?

  4. Natan says:

    Can you also include this in Language Injection? I have for example XQuery or SPARQL but they are usually tied to another file (XML, Java…) so without language injection they are quite useless and unreadable.

  5. Peter Gromov says:

    Hans, Leonidos, I personally would be glad if there was such a DSL. But the development resources are limited, and we don’t generally need it ourselves, so substantial investments into such support are not too likely. If only someone would like to contribute…

    Slawek, this is possible by some hacking in IDEA CE sources, but AFAIK we don’t plan to release an editor separately. Though the plans may always change.

    Natan, that’s a bit hard because the custom file type is a file type and what you inject is a language, and these are different notions. But I agree that would be a good idea. A YouTrack issue please?

  6. Colin Kershaw says:

    Is there a place to share custom file types for IntelliJ? Kind of like your plugin repository… but a file type repository. :)

  7. Peter Gromov says:

    Colin, not yet. But feel free to file a feature request.

  8. TIm Hepner says:

    If custom file types were available in the Settings->Inspections dialogue this would be a lot better.

  9. yole says:

    Tim,
    How they could be available? Inspections don’t know anything about custom file types. If you want to provide your own inspections for a file type, you can do so by writing a plugin.

  10. Kevin says:

    I love IDEA and use it for all of my projects. Especially for Javascript it’s an absolutely fantastic editor. But I do a lot of editing in non-standard languages (or even entirely custom grammars). The ability to add a language is crucial, for me, and I find it to be one of the most painful parts of the IDEA experience. Adding a new language is easy, but setting up the keywords is tedious. I frequently deal with upwards of 1000 keywords for a single grammar. I need to be able to supply those keywords in a text area. Doing it one at a time is too painful.

  11. Peter Gromov says:

    Kevin, sounds reasonable. Feature request please?

  12. Toar Schell says:

    I like the idea of simple syntax highlighting..I wish to add gawk/awk to my current project, and I have stumbled upon the idea of just modifiying the perl file type (its editable and has room for keywords. Only the Key words have to be added one at a time. Any chance they can be bulk imported? Is there an xml stored somewhere that can be modified?

  13. Peter Gromov says:

    Toar Shell, there’s an XML in config/filetypes. Please see http://devnet.jetbrains.net/docs/DOC-181 for the config directory location. File modifications while IDEA is running may not be applied.

  14. Chris says:

    Hi. Nice feature. Any idea what it means if I’m not allowed to insert any comments into a file with my new type? The file type gets recognized ok, the keywords are highlighted, but I can’t comment out code, neither line nor block. The option is greyed out in the menu.

    Cheers,
    Chris

  15. gromopetr says:

    Chris, this sounds strange. Could you please file a YouTrack issue (http://youtrack.jetbrains.com/dashboard) and provide screenshots of your file type configuration there?

  16. Brian Takita says:

    I would like to have a custom format for a simple indentation-based files.

    foo
    bar
    baz
    quux

  17. Will says:

    how can i write my own file designer to edit my file type instead of language based text editor. Just like an Android UI designer, or configuration designer . How can i do that? really need help

    • Peter Gromov says:

      It’s only achievable via a plugin, and it’s not an easy task. The starting point is implementing com.intellij.openapi.fileEditor.FileEditorProvider.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">