Live Templates in JavaScript/ActionScript/Flex
January 28th, 2010 by Alexander DoroshkoWriting JavaScript/ActionScript/Flex code becomes easier with IntelliJ IDEA 9.0.2. New set of live templates (see Settings dialog (Ctrl+Alt+S), Live Templates, JavaScript/ActionScript group), allows to avoid tedious typing when you need to define a function, variable or constant, to loop over an Array, Vector or anything else. Luckily, some abbreviations are the same as with Java: iter, itar, ritar. Here’s the list of currently available live templates:
| Abbreviation | Description |
|---|---|
| iter | Iterate (for each..in) |
| itin | Iterate (for..in) |
| itar | Iterate elements of array |
| ritar | Iterate elements of array in reverse order |
| pf | public function |
| prf | private function |
| psf | public static function |
| prsf | private static function |
| pv | public var |
| prv | private var |
| psv | public static var |
| prsv | private static var |
| pc | public const |
| prc | private const |
| psc | public static const |
| prsc | private static const |
To use a live template, just type its abbreviation anywhere in your code and press Tab. Here are some examples:
Ctrl+J shortcut shows you all live templates available for current context.
Also you may add your own live templates at Settings (Ctrl+Alt+S), Live Templates page.
Tags: ActionScript, Flex, JavaScript, Live Templates, Maia



February 5th, 2010 at 12:22 pm
Are you planning to provide an ability to generate class setters that use method chaining technique?
http://en.wikipedia.org/wiki/Method_chaining
Thanks!
February 5th, 2010 at 12:41 pm
nick99, I’m afraid I don’t understand your question in context of Flex iterations live templates. Flex setters return void by definition.
You may discuss your question at our forum: http://www.jetbrains.net/devnet/community/idea/ideacommunity
February 24th, 2010 at 10:22 am
Because of the lack of block scope in ActionScript 3.0, it’d be nice if the iterator abbreviations put variable declaration at the top of the containing function, since that’s where they will first come into scope.
Otherwise, the second use in a function will cause compile errors.
Another option - and perhaps it’s in there - I haven’t actually started eval of IDEA for ActionScript yet - would be to have a refactor option to hoist a variable declaration.
February 26th, 2010 at 3:30 am
Sindisil,
the second local variable declaration causes only compiler warning, but compilation succeeds. It is very easy to manually tune live templates to better match your code style: see Settings (Ctrl+Alt+S), Live Templates node, JavaScript/ActionScript group. Though the logic of placing variable definition as the first statement in current function and only if not yet defined is not achievable by live templates paradigm.
Ctrl+Shift+Up/Down arrows move statements up and down the code.
February 28th, 2010 at 9:19 am
Are you starting the support for live templates that comes close to Java? Like finding the variable for a certain type etc.?
March 1st, 2010 at 3:27 am
We’ve added a number of live templates like
pv: public var
prv: private var
psv: public static var
prsv: private static var
and similar for functions and constants.
Please open YouTrack request for more templates that you would like to have.
May 31st, 2010 at 4:49 am
The live templates can’t be modified. Every time I modify them the modification exists until I restart the IDE.
Can you acknowledge this?
November 6th, 2011 at 8:28 pm
On the mac/pc where can I find the complete list of all live templates and expansions? It is too tedious to navigate to the help and I can’t learn them by doing that. Thank you.
November 7th, 2011 at 7:31 am
Anne, all templates available in context are shown by Ctrl+J (Meta+J on Mac). To see all templates, configure them and create own ones see File | Settings | Live Templates.
December 1st, 2011 at 2:30 am
Live templates seem quite buggy in 11 Beta. +1 for Joa’s suggestion
December 1st, 2011 at 8:29 am
Pete, what are bugs? I don’t see any.
Requests for more live templates submitted to http://youtrack.jetbrains.net have good chances to be implemented.
December 1st, 2011 at 10:05 am
I have a template that just isn’t recognised at all (all contexts ticked) whilst I have another that works.
December 1st, 2011 at 10:09 am
Alexander CMD+J does show it and it’s selectable from there. But typing it inline doesn’t work. It’s called “tSilence” if that helps at all.
Thanks
Pete
December 1st, 2011 at 10:10 am
May be abbreviation conflict. Try to change abbreviation of your custom template. Is it listed in Ctrl+J popup in any context?
December 1st, 2011 at 10:13 am
Please make sure that you haven’t occasionally changed ‘Expand with’ key in respective combo in right bottom corner of Live Templates settings
December 2nd, 2011 at 8:35 am
Changing abbreviation doesn’t help. Expand with is the same as the others that do work “default (Tab)”. I have a couple that don’t work inline but show up under CMD+J.
December 2nd, 2011 at 8:51 am
@Pete Can you please open YouTrack issue and attach zipped content of your [IDEA config folder]/templates/ (standard location of [IDEA config folder] on Mac is ~/Library/Preferences/IntelliJIdeaXX).