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
Related
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.
I am able to format my Java code by configuring it in Save Actions.
What I get after Saving the file is that the whole code gets formatted according to my settings. What I need is, that only a part of code gets formatted according to the settings.
Say, there are 10 methods in my code and I add one more to it. What I want is that only my 11th method gets formatted and the previous 10 gets untouched.
Is that possible? I am using Eclipse Mars
NOTE:
The format includes, removing unnecessary casts, parenthesis, etc.
Source code formatting on save can be limited to edited lines only:
The other save actions however are applied to the whole file.
Select the text you want to format, and press Ctrl + Shift + F to format the selection.
Alternatively you can do Ctrl + I on the selected text to just correct the indentation.
I always use CTRL + SHIFT + F to format my code. In eclipse you can just drag your mouse and select the code you want, then press CTRL + SHIFT + F. That way it will just format the selected code.
Normal the Ctrl+Shift+F will format the current class. Or when a selection is made, only that selected part will be formated.
To make a quick selection, from the current place, use Ctrl+Shift+Arrow-Up to make it bigger. Or Ctrl+Shift+Arrow-Down to make it smaller again.
Telling Eclipse "manually" which parts of your code to format and which not can be a daunting task. Especially if others work on the same project and don't know which parts of the code have to be left out.
Because of this Eclipse allows you to set "markers", simply surround your code with these tags:
// #formatter:off
Here goes your code
// #formatter:on
In order to make this work you have to adjust the Java Code Formatter (it can be reached via Window / Preferences) settings like this:
As far as I know this has been in Eclipse since version 3.6.
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
By default, pressing the Comment out shortcut keys Ctrl + /, has behavior like this:
Notice that the // get added at the left-most position of the row.
Is there a way to set it so that the // appear at the same level of indention as the code that is being commented out?
e.g.
Perhaps a Python habit, but I find it much easier to parse when everything is at the same indention level.
Is there a way to change where the slashes show up?
Yes, it's possible.
go to this link for detailed info
First go to Preferences, then
On the left side of the box, expand the Java option, then expand Code
Style and finally click Formatter
You'll land on the Java-Profile page:
The other, temporary way is via CTRL+SHIFT+F shortcut ( Eclipse: Change the block comment style of ctrl+shift+/ ) . So you'd highlight those comments, and press the combo.
I would then also use a shortcut for CTRL+SHIFT+F , like ALT+F5 (press CTRL+3 , 'keys' to get the preferences page.
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