I am wondering is there a shortcut that can replace a variable name with a new name on multiple lines in the current Java file for IntelliJ. Is it just simply doing a find and replace operation, but it can't really solve the problem obviously.
Try to set cursor on variable and use shortcut Shift-F6 - after that there are dialog frame for change name of variable and it changes all occurences of variable to setted name.
Also, you can use shortcut Ctrl-Shift-R for replacing any word in project, it is useful if you working with huge project or your variable appears in config files.
Steps:
1: Put the cursor on the variable
ex:
Press shift+f6
Enter the name you want in the appeared dialogue box
ex:
Hit the Refactor button
Select your variable by right click > select refactor > rename
And rest all will be taken care by ide itself
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.
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
Lets say I have this method signature:
public String get(){};
Is there any shortcut in IntelliJ to highlight String and surround it with List<> So I can get the following:
public List<String> get(){};
You can make your own Surround Live Template:
Go to Settings/Preferences > IDE Settings > Live Templates > surround.
Add a new template.
Fill in the form
The abbreviation is used to select from the Surround With context menu.
The Description will appear in the Surround With context menu.
The $SELECTION$ variable is predefined as, you guessed it, the selected text.
You can add your own variables, such as $COLL$ to make the template more generic.
Set the Applicable in... to all of Java (or you can be more exact if you want).
To use it:
Select text.
Press Ctrl+Alt+T on Windows or ⌥⌘T on Mac
The Surround With context menu will appear with your new template.
Press C (since that's the first letter of the template's abbreviation) to quickly select the template.
IntelliJ blog post about this feature: "Surround with..."
Thanks for the answer and this is how we can create a variable :
Hi I'm new to IntelliJ IDEA and got here and there usability issues, because I'm coming from Eclipse.
When I rename a variable and want to mark the second part of it by hitting Ctrl+Shift+Right, the cursor moves to the next word which is outside of the border for renaming and when I type the new name and click Enter, the rename isn't executed for the other usages of the variable. Is there a setting where it's possible to change the behavior of Ctrl+Shift+Left/Right so that the caret moves right after the last character of the variable name?
Second question
When I'm moving the cursor through a variable name with Ctrl+Left/Right the next stop in Eclipse was always before the next upper case letter. Is in Idea also a setting to activate this? This would be very helpful when renaming variables.
What you exactly need is [I have jIdea 12.1]:
Go to settings [Ctrl+Alt+S]
Choose [Editor -> General -> Smartkeys]
Check the [Use "CamelHumps" Words] button
Вуаля!
Ctrl+Alt+S and select Keymap from settings, you can change what you want it to there.
But I would suggest using the autocomplete/intellitext features of IntelliJ and the refactoring tool, without manually navigating through variable names - they normally get it right first time.
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