Custom file types in IntelliJ IDEA
September 14th, 2010 by Peter GromovIntelliJ 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:

Tags: Code Completion, Editor, Haskell

September 14th, 2010 at 5:54 am
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?
September 14th, 2010 at 11:32 am
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
September 14th, 2010 at 2:52 pm
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?
September 15th, 2010 at 2:48 am
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.
September 15th, 2010 at 5:43 am
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?
January 20th, 2011 at 1:26 pm
Is there a place to share custom file types for IntelliJ? Kind of like your plugin repository… but a file type repository.
January 21st, 2011 at 2:46 pm
Colin, not yet. But feel free to file a feature request.
November 17th, 2011 at 3:00 pm
If custom file types were available in the Settings->Inspections dialogue this would be a lot better.
November 18th, 2011 at 2:35 am
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.
July 25th, 2012 at 3:06 am
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.
July 26th, 2012 at 6:11 am
Kevin, sounds reasonable. Feature request please?
October 2nd, 2012 at 1:47 pm
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?
October 4th, 2012 at 4:59 am
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.