Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

webstorm

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

like image 253
Peter Kellner Avatar asked Nov 11 '14 16:11

Peter Kellner


People also ask

How do I navigate in Webstorm?

Navigate to a file with the Navigation bar Use the Navigation bar as a handy tool to find your way across the project. Press Alt+Home to activate the Navigation bar. Use the arrow keys or the mouse pointer to locate the desired file.

How do I surround the code with if for try catch in IntelliJ Mac?

Simply select the code block to surround (don't forget to use Ctrl + W to increase the current selection) and then press Ctrl + Alt + T (or right-click the selection and select Surround with… from the menu). IntelliJ IDEA will show a list of options to choose from.

How to use WebStorm shortcuts?

These are most used shortcuts of WebStorm. The complete list can be found under File menu > Settings > Keymap. matches. . To see every shortcut, go to the full page . Find Action. This command allows you to search in all commands and settings Another way to learn shortcuts is to use Key Promoter X plugin.

How do I search for a specific action in WebStorm?

While there, you can search by action name or by shortcut: Alternatively, start typing an action name in the Search everywhere popup, and you’ll see some matching shortcuts. Also you can also try Visual Shortcut Mapper with the WebStorm default keymap available.

How do I get a WebStorm keymap reference?

If you prefer a hard copy, download the default WebStorm keymap reference and print it out as a card: WebStorm provides several possibilities to learn shortcuts: Find Action lets you search for commands and settings across all menus and tools. Press Ctrl+Shift+A and start typing to get a list of suggested actions.

How do I jump to a symbol in WebStorm?

With WebStorm, you can instantly jump to the definition of a symbol: just press ⌘ or Ctrl and click on that symbol, or place the caret on it and press ⌘B / Ctrl+B. This shortcut can also help you jump to the referenced file or imported module.


1 Answers

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)

like image 67
lena Avatar answered Oct 26 '22 23:10

lena