Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a shortcut for wrapping a statement with system.out.println in IntelliJ

It appears to me that sometimes I want to print the values of a variable, so I repeat the following actions:

  1. write sout TAB (shortcut for system.out.println)
  2. write the variable name inside the function

Is it possible in IntelliJ to wrap a variable with a function, using keyboard shortcuts only?

like image 957
itamarb Avatar asked Jan 01 '13 17:01

itamarb


People also ask

What is the fastest way to write system out Println in IntelliJ?

In IDEA, you can type sout and press Tab to generate System. out. println automatically.

What is Ctrl Shift O in IntelliJ?

In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For IntelliJ IDEA, if you press CTRL + ALT + O “Optimize Imports”, it just removes some unused imports, never imports any package.

How do you wrap lines in IntelliJ?

You can enable soft wrap for the editor with ⇧⇧ (macOS), or *Shift+Shift (Windows/Linux), for the Search Everywhere dialogue, and then typing in soft wrap. You can also go to Preferences/Settings > Editor > General to enable Soft Wraps for more file types by default.


1 Answers

In Intellij Idea 13.1, there is a shortcut way called "postfix code completion".

So, to wrap an expression, object or variable with System.out.println, you simply write its name, put a dot then write sout, then hit tab. So, for example:

new MyObject().sout + <tab>   

will be converted to

System.out.println(new MyObject()) 

More examples:

"Hello World!".sout  int myVariable = 5; myVariable.sout 

You can get more information about postfix completions on this page: http://blog.jetbrains.com/idea/2014/03/postfix-completion/

like image 93
Utku Özdemir Avatar answered Oct 08 '22 03:10

Utku Özdemir