Eclipse | code template for System.out.println() - java

I have got the following as the code template for System.out.println in Eclipse
System.out.println(${word_selection}${});${cursor}
I was under the impression that I could write a text, select it, enter ctrl+space, and then write sop - and Eclipse will write the proper line for me. But this is not happening. Can anyone help me understand the way ${word_selection} is supposed to work?

You need to select the text and press ctrl+space twice. The first time you do it, "default proposals" are shown. The next time the applicable code templates are shown. Unfortunately you cannot type the name of the template since that will overwrite the selected text, but you can select it with arrow keys and press return.
It will look like this after the second ctrl+space on an Eclipse with default templates:

Related

How can I change the post fix template in Eclipse? [duplicate]

I am aware of the Eclipse snippet "sysout" which is neatly replaced with System.out.println(); when tab-completed.
This is very useful but sometimes, I need to wrap some existing code in a System.out.println();
In Eclipse internals, the template is defined as being able to wrap a "selected word". But how can I use the snippet with selected text since typing "sysout" obviously removes the selected text.
Any idea?
The sysout template acts upon entire Java statements.
Highlight a statement in the editor.
Hit CTRL-SPACE (or whatever you have set up for content assist.)
Type sysout then hit enter. Note that when you're typing sysout it will temporarily overwrite your statement (but it will come back wrapped by System.out.println when you hit enter.)
Eclipse has "Surround Width" Option which can do this for you.
SHIFT + ALT + Z should get you that to see how that templates meta-data layout.
I don't think you can do it in one go, but what about cutting the selected text and then: tab+space, ctrl+v
it's just one key combination more.
if you use content assist (ctrl-space on Windows), at the end of the list will be the sysout option. you might want to augment the template with quotes around the word selection so you dont need to type them in.
Preference>General>Keys.
then search "content assist" or "content" in "type filter text".
don't press Enter.
choice "content assist".
type Binding and set your own shortcuts.
such as "control+space".
The main part is into:
Java->Editor->Templates
This can accessed by:
Preferences window: into Java->Editor->Templates.
Surrounding a text and press:
Windows: SHIFT + ALT + Z (as sadhasivam said)
Mac: CMD + OPT + Z
to display the Preferences Window

Eclipse - Enclose selection instead of replacing

In Eclipse, when i select part of a text and press any key, the whole selection is replaced.
I would like to know how to make it, instead of replacing the text, add the key pressed to both ends of the selection, as it happens on visual studio code.
Example:
System.out.println(HelloWorld);
Select Hello World
System.out.println(HelloWorld);
Then press the " button. The code will turn to
System.out.println(");
Can i config the IDE so it will instead change it to
System.out.println("HelloWorld");
There is a already answered question like this one, but considering that one as 7 years and a lot of version old, and also considering that the answer on that one is kind of a work around, i would like to know if there's any new plugin or configuration that make it work better
From what I gather, you are wanting to do something like this?
Go to Java > Editor > Templates and add a new template, e. g. called quote, as follows:
"${word_selection}"${cursor}
Then, in the editor, write a text you want to quote, select it, press Ctrl+Space, type quote and hit Return. The highlighted text should be quoted now.
If you don't get template proposals when pressing Ctrl+Space, make sure you have them checked in Java > Editor > Content Assist > Advanced.
Just tried it and it works for me!
You can use this method for other things, like (${word_selection})${cursor} for parenthesis or '${word_selection}'${cursor} for single quote.

Eclipse parameter dialog/hint when using functions in code

By default In Eclipse when you use a function or create objects it helps with parameters like this:
But once it's done, it'll never show up again. Is there any way to call this parameter helper on code that's already written when I point the cursor on the method?
The Image I uploaded only appears while writing code.
Ctrl + Shift + Space will do the trick. It is named Context information in Key preferences.
Place the cursor just inside the left parenthesis and press Ctrl+Space (Command+Space on Mac) again; Eclipse will show Content Assist again.
When the mouse cursor is in the paranthesis, click Ctrl+Space. It will pop up menu (content assist). If you enter it, it will show the context information as it was at the beginning.
You can't get place holders again once they disappeared. But you can get content assist help as said by #E-Riz
Check this answer What is Eclipse shortcut key to turn on feature that allows when pressing TAB key, for cursor to go to expected position? and also this What's this box around my function input?
i was looking for the same shortcut and didn't find it ;
now i'm using
*ctrl+Arrows to move between words
*alt+shift+arrows to select the world and replace it
JDT-Codemining is a new project (as of Aug 2018) that supports parameter hints, along with many other features, such as:
General
Show references
Show implementations
Show method parameter names
Show method parameter types
Show end statement
JUnit
Show JUnit status
Show JUnit run
Show JUnit debug
Debugging
Show variable values inline while debugging

Add piece of code to shortcut

Is there a way in Eclipse to bound a piece of code to a shortcut?
I use System.out.println() quite often, for testing and other things, and it would be so much easier if I had to press you ctrl + something instead of typing it out every time..
For System.out.println, you can type something like:
"test"
Then highlight it, press CTRL+Space, type sysout, and press enter.
As Pescis noted in the comments, you can also type sysout followed by CTRL+Space. It gives you the System.out.println(); with a focus inside the brackets. (Thanks Pescis!)
To create new templates, go to Window -> Preferences -> Java -> Editor -> Templates.
Here is a link to some ready-made templates, if you are interested.
Type syso and ctrl + space for System.out.println()

How to use the "sysout" snippet in Eclipse with selected text?

I am aware of the Eclipse snippet "sysout" which is neatly replaced with System.out.println(); when tab-completed.
This is very useful but sometimes, I need to wrap some existing code in a System.out.println();
In Eclipse internals, the template is defined as being able to wrap a "selected word". But how can I use the snippet with selected text since typing "sysout" obviously removes the selected text.
Any idea?
The sysout template acts upon entire Java statements.
Highlight a statement in the editor.
Hit CTRL-SPACE (or whatever you have set up for content assist.)
Type sysout then hit enter. Note that when you're typing sysout it will temporarily overwrite your statement (but it will come back wrapped by System.out.println when you hit enter.)
Eclipse has "Surround Width" Option which can do this for you.
SHIFT + ALT + Z should get you that to see how that templates meta-data layout.
I don't think you can do it in one go, but what about cutting the selected text and then: tab+space, ctrl+v
it's just one key combination more.
if you use content assist (ctrl-space on Windows), at the end of the list will be the sysout option. you might want to augment the template with quotes around the word selection so you dont need to type them in.
Preference>General>Keys.
then search "content assist" or "content" in "type filter text".
don't press Enter.
choice "content assist".
type Binding and set your own shortcuts.
such as "control+space".
The main part is into:
Java->Editor->Templates
This can accessed by:
Preferences window: into Java->Editor->Templates.
Surrounding a text and press:
Windows: SHIFT + ALT + Z (as sadhasivam said)
Mac: CMD + OPT + Z
to display the Preferences Window

Categories

Resources