webstorm

Any shortcut in WebStorm to surround a block of code with an IIFE


That is, if I have a function like:

angular.module('sessionController',[]);

and I want to change it to

(function () {
    'use strict';

     angular.module('sessionController',[]);

}());

I was thinking there would be a "code/surround with" type option.


Solution

  • You can create the corresponding Live Template (Settings/Live Templates) like the following:

    (function () {
        'use strict';
    
         $SELECTION$
    
    }());
    

    Make sure to set the context (Applicable In...) to 'JavaScript'.

    Template can be applied using Code/Surround with live template (Ctrl+Alt+J)