does webstorm have some shortcut for console.log or console.info

前端 未结 9 1949
野的像风
野的像风 2021-02-01 11:45

Just tired of typing console.log again and again, and do not find a way like \'Sysout + Control + Space\' in Eclipse will create System.out.println().

相关标签:
9条回答
  • 2021-02-01 12:32

    There's a predefined Postfix template that allows you to type .log after a JavaScript expression or string and hit Tab to transform it to console.log().

    You can also create a Live template (see Preferences | Editor | Live templates) that would expand into a code snippet once you type the selected abbreviation and hit Tab.

    Update: there's now also a plugin that allows you to add console.log with a shortcut: https://plugins.jetbrains.com/plugin/10986-console-log

    0 讨论(0)
  • 2021-02-01 12:32

    I'm including what I find to be the most efficient, which I added via live templates -> javascript -> applicable to "Everything". Hopefully someone finds it useful.

    console.log('L$LINE$ $MYSTRING$ ===', $MYVAR$);$END$

    What it does: When I type cl and press tab, it creates the log and the first thing you type fills both MYSTRING and MYVAR variables. If you tab again, it selects MYVAR where you can rewrite/delete as desired. The third time you hit tab will take you to the end of the line at $END. This snippet also prints the line number like L123 but you can easily remove that if it isn't helpful because obviously most browsers show line number anyway.

    You also have to set the variables' behaviour as seen in the image below:

    Edit variables setup

    0 讨论(0)
  • 2021-02-01 12:36

    use Macros!

    https://www.jetbrains.com/help/webstorm/using-macros-in-the-editor.html

    I recorded a macro that takes the name my cursor is on and create

    console.log("#### name = ", name);

    on the next line. and assigned a keyboard shortcut to it :)

    super easy, and couldn't get Live Template to get the same result with 1 action.

    to create a new macro: Edit -> Macros -> Start Macro Recording. then record your next moves and create the desired result. this is mine:

    0 讨论(0)
提交回复
热议问题