Eclipse special hotkey - print the current line to the standard

Eclipse has a useful hotkey for assigning the current line to a local variable - when I type for example:

Math.random() 

and press ALT + SHIFT + L (Extract local variable), I can quickly change the line to

 double random = Math.random(); 

I would like to use the same trick to print it in std, so that Math.random() changes to:

 System.out.println(Math.random()); 

Currently, a quick way to do this is to type syso and use the content help to use the template, but this requires manual copying. Does anyone know a better way to do this?

+4
source share
2 answers

Two possibilities come to my mind to achieve your goal, but both of them first require a choice of application.

After selecting an operator, press CTRL + SPACE , then type syso and press Enter . The selected statement will be placed inside the System.out block:

 System.out.println(statement); 

You can also prepare an eclipse template ( Window-> Preference-> Java-> Editor-> Content Assist-> Templates ) and give it some name:

 System.out.println(${line_selection});${cursor} 

After selecting the operator, press ALT + SHIFT + Z or select the menu item Source-> Volumetric menu (also in the context menu). The template you created should be there, so select it. The selected statement will be wrapped inside the desired code block.

+1
source

As far as I know, there is no shortcut in the preferences section. In this case, contextual help is not enough for you?

0
source

Source: https://habr.com/ru/post/1489263/


All Articles