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

你说的曾经没有我的故事 提交于 2019-12-02 19:55:24

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

Yes it does,

<anything>.log and press Tab key. This will result in console.log(<anything>);

ie,

<anything>.log + Tab => console.log(<anything>);


eg1: variable

let my_var = 'Hello, World!';
my_var.log + Tab => console.log(my_var);

eg2: string

'hello'.log + Tab => console.log('hello');

eg3: string and variable

'hello', my_var.log + Tab => console.log('hello', my_var);
ptnz

I made my own template that seems to work. It may be useful for somebody.

Abbreviation: ll

Template text:

console.log('$NAME$ ', $VALUE$);
    $END$

Variables: (just select the given field values by clicking drop down box)

  1. NAME - jsDefineParameter()
  2. VALUE - jsSuggestVariableName

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

I made a custom template. This can help you.

Abbreviation: clog

Template code:

console.log("\n\n--------------------------------");
console.log($END$);
console.log("--------------------------------\n\n");

Simplest live template text:

console.log($END$);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!