Live Templates in JavaScript/ActionScript/Flex

Writing 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
itin Iterate (
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.

This entry was posted in New Features and tagged , , , , . Bookmark the permalink.

17 Responses to Live Templates in JavaScript/ActionScript/Flex

  1. nick99 says:

    Are you planning to provide an ability to generate class setters that use method chaining technique?


  2. Alexander Doroshko says:

    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:

  3. Sindisil says:

    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.

  4. Alexander Doroshko says:

    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.

  5. Joa Ebert says:

    Are you starting the support for live templates that comes close to Java? Like finding the variable for a certain type etc.?

  6. Alexander Doroshko says:

    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.

  7. Kai says:

    The live templates can’t be modified. Every time I modify them the modification exists until I restart the IDE.
    Can you acknowledge this?

  8. Anne says:

    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.

  9. Alexander Doroshko says:

    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.

  10. Pete says:

    Live templates seem quite buggy in 11 Beta. +1 for Joa’s suggestion

  11. Alexander Doroshko says:

    Pete, what are bugs? I don’t see any.
    Requests for more live templates submitted to have good chances to be implemented.

  12. Pete says:

    I have a template that just isn’t recognised at all (all contexts ticked) whilst I have another that works.

  13. Pete says:

    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.


  14. Alexander Doroshko says:

    May be abbreviation conflict. Try to change abbreviation of your custom template. Is it listed in Ctrl+J popup in any context?

  15. Alexander Doroshko says:

    Please make sure that you haven’t occasionally changed ‘Expand with’ key in respective combo in right bottom corner of Live Templates settings

  16. Pete says:

    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.

  17. Alexander Doroshko says:

    @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).

Leave a Reply

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