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.
Related
This question already has answers here:
Ctrl + Space not working for content assist on eclipse
(12 answers)
Closed 4 years ago.
This was wrongly flagged as a duplicate, so I can't answer. I found a solution: Since version 2018-12 there's the option to disable all insertion triggers except enter (under Preferences>Java>Editor>Content Assist). This is exactly what i wanted
Using java content assist, I sometimes come across certain cases where the popup with suggestions opens itself but I just want to keep typing.
However, since typing space or ( for some reason takes the currently selected suggestion and closes the popup, I sometimes end up having to delete the inserted suggestion by hand which takes some time.
Is there some way I can configure that I do not want space or ( to select the suggestion but instead just type in the character, effectively closing the content assist popup? If not, are there plugins for this?
Help is greatly appreciated.
Clarification why this is not a duplicate: CTRL + Space are opening content assist for me. That is not the problem.
My problem is what actually completes the suggestion from content assist. E.g. suppose I have logger utility with a method called log(param1, param2, param3, ...); with 7 parameters and a method log(param1); with 1 parameter.
I have contest assist enabled on . presses so if I type this.log the content assist popup will be open and prompting me with log(7 parameters) and log(1 parameter).
If I typed too fast and didn't realize content assist opening, and now type a ( after the this.log, the content assist will automatically choose the first suggestion with 7 parameters for me and insert it into my code, instead of just letting me type the (
I want to know if I can disable that space, ( or ; insert the suggestion from content assist. Is there a setting or a plugin e.g. for enabling only Enter to fill in the suggestion?
Open up Eclipse, in the top bar to the right click on "Window".
Then, click "Preferences" (should be at the bottom)
A window should pop up and type in the tool bar "typing".
There should be a left side bar, click on Typing, located under Java
and you should be able to uncheck whatever auto assist you desire.
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:
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
I'm trying to add a line break with the Find function in eclipse - What I want to do is put a line after each method in all my classes [I liked them all close together but now its hard to read through]. so I figure theres 2 ways to do this.
1. Find all with "public" and change to "\npublic", \n being the new line in a string to give you the idea of what I mean.
2. A convenient eclipse shortcut that separates all the methods in a class with an empty line.
Any ideas on how to achieve this? I'll be happy as long as it works and I don't have to go through every method in the project myself and push enter .-.
For #2, you can set the Eclipse auto-formatter to do so for you.
Look under the Preferences panel; in the left side (tree), select Java Code Style (click the arrow to expand the section), then Formatter. You can then decide to use a single formatting style for all of your projects, or check the box to apply a special set of formatting rules to just the current project. Some of the options include where to locate whitespace and newlines.
You can also use the “Save Actions” panel to re-apply the same formatting rules every time you save your files. Personally, I use (and team members as well) this method, to ensure that the formatting for the files is always consistent. By mechanically reformatting in this way, changes to the file will always show up “properly” in Subversion/Git — I don't accidentally have whitespace-only changes being introduced into files showing up as “false positive” changes.
Check box 'Regular Expressions' and use '\R' for Linebreak in the 'Replace with' box in eclipse
configure the auto-formatter its a bit of work for the first time but its worth, when ever you get ugly formatted code you can fix this in seconds ..
I'm finally making the voyage back to IntelliJ via Eclipse. Currently my Eclipse is set up so that if I currently have a statement such as this (where ^ denotes where my cursor currently sits):
foo.bar("hello"^)
and I hit the semi-colon (;) key, it will automatically put the semi-colon at the end of the statement:
foo.bar("hello");
Currently IntelliJ does this:
foo.bar("hello";)
Meaning I will have to explicitly type the closing bracket before typing the semi-colon.
Not a huge problem obviously but I have found myself putting the semi-colon in the wrong place a few times today as I make the transition back to IntelliJ and thought that it may be more efficient (for both my fingers and brain) not to have to type the closing bracket.
For Windows or Linux users, Ctrl+Shift+Enter.
For macOS/OS X users, ⌘ Command+⇧ Shift+Enter.
That finishes the statement you're currently writing. Try it in a few different situations, like in if statements, for loops etc, and you'll see that it'll complete the line and open some curly braces for you if necessary.
You can add a keymap of your own. I added Ctrl+; to my Keymaps for the "Complete Current Statement" action. This saved me an extra key stroke and made it a little bit more intuitive.
Go to Settings > Keymap
In the search box, enter "Complete Current Statement".
Right-click on the entry and select "Add Keyboard shortcut"
With the First Stroke field hightlighted, enter your key combination. E.g., Ctrl+;, which will display as Ctrl+Semicolon
Click OK, and OK to save and exit.
You can opt to remove or keep the existing mapping. Should look something like this when you're done:
if you want always have it just do this