Smart typing in Intellij IDEA - intellij-idea

I'm using Intellij IDEA for about a year and I still wonder if there is some type of smart shortcut for this scenario:
new In|[ENTER]
new Integer(|)
new Integer(10|)
new Integer(10|)[RIGHT ARROW]
new Integer(10).| (any method name)
This may sounds silly, but I find myself using the right arrow too much during my work day, so I'm looking for a simple solution to skip this part when typing. Is there any smart shortcut in Intellij IDEA to start typing method name (with dot ahead) while the caret is still where the arguments are (inside parentheses)?

You can create your own macro and assign a Keymap to it like so*:
Edit | Macros | Start Macro Recording
Perform the sequence of steps, ⌘→ followed by .
Edit | Macros | Stop Macro Recording
Name the macro, e.g. "Go to line end and start method"
In Settings, search for the macro name (to make it easier to find), select in Keymap | Macros
Right-click and select Add Keyboard Shortcut, assign the "First Stroke" to ⌃⇧., for example
OK all the dialogs and try it out!
* These are the steps on Mac, there might be slight differences for other OSs.

Related

Mapping Keyboard Shortcuts in Word (vba) KeyBindings.Add KeyCategory: = wdKeyCategoryCommand, Command: = "..."

Good day.
Someone has a list of the commands that can be assigned a keyboard shortcut using the function:
KeyBindings.Add KeyCategory: = wdKeyCategoryCommand, Command: = "..."
I want to assign a shortcut to decreasing French indentation, but I only see the command for its increase: Command: = "HangingIndent"
Thank you. Greetings.
Choose Developer>Macros. Change the Macros in dropdown to Word commands. The complete list of available command names is displayed.
If you need to set specific indentation amounts, you'll have to write a simple macro instead of relying on Word's preset indentation values.
But it's probably better to avoid VBA altogether. Instead of relying on local formatting (which a Word command or macro would do), create a typestyle with your preferred indentation and apply that to the text. That's a better practice in Word and easy to update later if you change your mind about the amount of indentation.
The problem is precisely that, that the command related to the decrease of the French indentation does not appear in the list of Word commands. What I need to know is what the said command is called. After a lot of thinking I found a command to list all the keyboard shortcuts in the active document: Application.Run MacroName: =" CommandList" and this allowed me to find what I'm looking for: RemoveHangingIndent

How to go to next/previous occurrence in current editor tab?

In eclipse, you can go to the previous/next occurrence of the selected word by pressing ctrl+, / ctrl+..
What is the equivalent in IntelliJ IDEA?
The feature is called Find Word at Caret:
Search for a word at caret enables you to quickly find the exact match for the current word, without changing any search options. With the match once found, you can navigate between the occurrences of the term.
You can use Ctrl+F3 for that:
select a word at caret
hit Ctrl+F3 and then F3 or Shift+F3 to navigate to the
next/previous occurrence
Mac OS
Please note that there is no shortcut on Mac OS. You'd need to use Cmd+Shift+a and type "Find Word At Caret" ("find wo" should be enough) or on the main menu, choose Edit | Find | Find Word At Caret. Press Cmd+g to navigate to go to the next occurrence.
Separate Plugin
Or, try this plugin - it supports using Shift+Alt+Up and Shift+Alt+Down to navigate up and down to each identifier occurrence
To make this feature available by default please, vote for IDEA-59638
Use Ctrl+Shift+F7 to highlight the usages of some variable in the current file, then use F3 or Shift+F3 to navigate through the highlighted usages.
(It works in IntelliJ IDEA 2016.1.3)
Finding Word at Caret: Ctrl+F3:
Search for a word at caret enables you to quickly find the exact match for the current word, without changing any search options. With the match once found, you can navigate between the occurrences of the term.
Note that after it has found occurrences, it immediately goes to the first occurrence.
The functions for this are called Go to {next,previous} highlighted element usage and are available by default only via the menu Edit→Find. No key press is associated to this function by default. (IntelliJ IDEA 2018.3 (Community Edition))
You can set them to a specific key press in the keymap: File→Settings→Keymap→Main menu→Edit→Find and double click on the function you want to set.
EDIT:
IntelliJ IDEA 2021.3 (Community Edition): via main menu Edit→Find Usage→Next(Previous) Highlighted Usage
CMD + Shift + F7 to select all occurrences
than CMD + G to navigate forward
CMD + Shift + G to navigate backward

IntelliJ navigate to next and previous highlighted variable

In IntelliJ 10.5 I have "Highlight usages of element at caret" enabled. When a variable/method/etc is selected, is there a way to move to the next and previous occurrence? I'm looking for the equivalent of Control-K in Eclipse.
Edit: Shortcut to navigate between highlighted usages simply moves to the next text occurrence, which is different than moving to the next occurrence of the variable/method/etc. If I have the variable foo selected, I want to navigate to the next occurrence of foo and not any piece of text called "foo" (including "foo" in comments, method names, etc).
Also, pressing F3 seems to be buggy. When I press F3, it sometimes searches using the previous searched text and not the currently highlighted text.
F3 or shift+F3
ctrl+c, ctrl+f, enter or up and down arrows
ctrl+alt+F7
Added this in case people don't look at your edit.
It's not currently possible, see my question: Shortcut to navigate between highlighted usages.
I even created an issue IDEA-70523 addressing this feature, please vote for it if you can't live without it like me :-).
Install Identifier Highlighter Reloaded and use Alt + Shift + Up/Down (can be redefined in Keymap settings) :)
After you give it a shot and notice the 'hey, the highlight stays there after I move my cursor out of it' annoyance, consider upvoting this issue :)
In the Mac OS, you can navigate to next highlighted usage by press control + option + up/down arrow.
Vote this request up for make them implement the feature.
http://youtrack.jetbrains.com/issue/IDEA-59638
I found something thay may more suite your needs : alt + mouse-wheel up/down.
It goes to previous / next occurrence of identifier under caret.
Shortcut name is "Go to next highlighted element usage".
I usually do the following:
Highlight the word
Cmd + F (it will highlight all the matches in file)
Cmd + G (next match)
Cmd + Shift + G (previous match)
I could not get any of IntelliJ's native options for Find Next/Previous to behave like in Eclipse. Find Word at Caret comes close, but it only allows you to slurp and find the next word, not previous.
Identifier Highlighter Reloaded also does not behave like Eclipse.
I wrote an IntelliJ plugin to reproduce the exact behavior as in Eclipse. You can find it here: https://plugins.jetbrains.com/plugin/10635-quick-find-plugin
Look for next occurrence # Keymap
^G = "select" the variable that you want to search for
[shift]⌘G = [previous]next occurrence of selected variable
All credits to #Igor Wojda for his comment in the accepted answer.
(AFAIK, limiting search scope to only variable/method is not possible)
For text based match and quick jump:
Simply place the cursor over the desired word to be searched
Press Ctrl+F3
For further down/up search, simply use
F3/Shift+F3 respectively
in Intellij shortcut for this action, it's not defined.
but you can define it like this:
Ctrl+ Alt + S
search " highlighted usage"
then you can set a shortcut for that.
Ctrl+Alt+Up and Ctrl+Alt+Down navigates to the next and previous usages of a highlighted variable in IntelliJ.
I use this functionality of navigating to the next usage of a variable in a file by hot in Visual Studio all the time (Ctrl+Shift+Up and Ctrl+Shift+Down) and was looking for the equivalent in IntelliJ

Make IntelliJ reformat the current line on line-completion

Is there a way to have my line reformatted upon completing it in IntelliJ? (For those familiar, this kind of feature is available on FlashDevelop.)
Let's says I just entered this code in PHP:
$var=array("a","b","c");
Upon entering the semicolon, I would like the editor to reformat it to (or whatever my configuration states):
$var = array("a", "b", "c");
This auto-reformat trigger could also be executed on brackets and other line-terminators characters.
There is no such feature in IDEA. You can use Reformat Code (Ctrl + Alt + L) action when needed.
You can actually do something like.
Go to where you want to insert ;
Tools/Start Macro Recording
Type in ;
Then select Code/Auto Indent Lines
Tools/Stop Macro Recording
Name the macro "reformat"
Now go to settings, Keymap, Macros, select "reformat"
Assign a keyboard shortcut of ;
You may have to play with it a bit to get your cursor in the right spot after the macro runs.
This is based on jhormans answer above and i know that the question is more than 6 years old. But IntelliJ IDEA 2017.1.5 still does not have a feature that automatically reformats the current line when semicolon is pressed like VisualStudios.
The workaround is to create a macro as described by jhorman but after pressing ';' run Code -> Reformat Code. Then stop recording and under Settings/Keymap/Macros add the shortcut "Shift+Comma" to the macro. Now when typing the semicolon by pressing Shift + Comma in the code, the code will be reformated aswell. The only shortcoming: the whole code will be reformated each time Shift+Comma is pressed. This may take a second on large files.
This workaround will only work if you just have one line terminator like semicolon. To automatically reformat the code on multiple line terminators (closing brackets, semicolon, ...) you would need to add the shortcuts to "Settings" -> "Keymap" -> "Main Menu" -> "Code" -> "Reformat Code" directly. In this case there's no need to create a macro.
Just formatting the current line isn't possible as far as i know.

Intellij New line on current line shortcut

Is there a keyboard shortcut to start a new line on the currently selected line?
I.e. The current line goes down one line and the cursor is on a blank line.
There is Shift + Enter which starts a new line but on the next line. I want the current line.
CTRL+ALT+ENTER was the right shortcut for me (version 12.1.6).
CTRL+SHIFT+ENTER works as of 11.2.
On mac this works for me:
⌘+ ⌥ + ↵
There isn't one, but you can very easily create it using a macro.
In order to create the macro you can follow these steps:
Place the cursor on any line with code.
Click on menu Tools | Start Macro Recording
Press: Home -> Enter -> Up
Click on menu Tools | Stop Macro Recording
Test your macro using Tools | Playback Last Macro
You can remove any action from the macro that doesn't belong there by using Tools | Edit Macros.
When the macro is working fine you can assign a shortcut to it in the Settings window on the Keymap page.
Do not think anything exists in version IntelliJ 8 or 9 for that matter. Prove me wrong.