Intellij New line on current line shortcut - intellij-idea

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.

Related

Adding spaces in multiple lines simultaneously - in Pycharm

I occasionally need to go line-by line and change the indentation of the code.
Is there a shortcut in Pycharm where I can add spaces (format the indent) in the begining of multiple lines simultaneously without processing each line individually?
Highlight/ select the lines you want indented, then press TAB as often as needed until they reach the proper indent level.
You can remove spaces with SHIFT TAB.
You can also use CTRL+ALT+I to auto-indent the selection.
Select the block that you want to indent then press TAB. It will work.
To auto indent all the codes in Pycharm just press these sequencies:
CTR + A to select all the text files and then press
CTRL+ALT+I
Select all that you want to indent, then do CTRL+ALT+I to indent all of it. This should work in Pycharm
Use shift +alt on windows machine
Continuation indent for Mac pro: Preferences -> Editor -> Code Style -> the language -> Tabs and Indents
If Ctrl + ALT + I is not working and every time needs to press the Insert button to get the pointer.
So go to Tools -> Select Vim if it is checked then it will be disabled.
Now you can intend code directly selecting multiple lines.

Smart typing in 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.

What is the shortcut to find next occurrence of a word in IntelliJ IDEA?

In Eclipse the keyboard shortcut to find next occurrence of a word in a file was Ctrl + k . It finds the occurrence of the selected word in a file one by one in a loop. What is the equivalent keyboard shortcut for IntelliJ IDEA? If not can we configure it some how?
First you'll have to highlight a symbol by pressing Ctrl+Shift+F7.
Then you just press F3 or Shift+F3 no navigate between the highlighted symbols.
When done you press Esc to exit the highlight searching.
It is all described on Highlightning Usages in IntelliJ Web Help.
Add selection for the next occurrence on Linux Alt+J
Finding Word at Caret: Ctrl+F3.
On Mac it's Command + G, but you can check what works for your OS by looking at Edit -> Find -> Find Next....
AFAIK you have to select the word in the search bar first.. So, Command + F and then Command + G to go to the next occurrence.
In Android Studio 1.4, apparently Mac OS default keyboard shortcuts for element next occurrence (vars, methods, etc) are
NEXT/FWD: Command+G
PREVIOUS: Shift+Command+G
I did try all the answers w/out success, and finally I looked it up in Prefs->Key Bindings
There are also hotkeys for navigating next/previous highlighted usages.
Several years ago they were Alt+Wheel down and Alt+Wheel up. Today they are not set by default.
You can find them in Keymap preferences with highlighted element usage search phrase.
Please consider using the Multiple Selections for this:
Select the term you want to lookup;
Use Alt+J / Shift+Alt+J (or Ctrl+G / Shift+Ctrl+G for Mac OS X) to select other occurrences.
It will work the same as Shift+F3, but it will select every next occurrences. I found this way much more conveniant, as you can choose to edit all the matching string or just move the cursor to edit the last selected one (←/→).
The Multiple Selections feature is available since IntelliJ IDEA 13.1 RC, and compete with Atom or Sublime Text similar feature.
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.
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
you can set shortcuts same as in eclipse by setting keymap value as eclipse.
Steps in intellij:
Go to setting in file
search for keymap
In the dropdown section set Eclipse
Now all your shortcuts are same as in eclipse.
For MAC:
First you'll have to highlight a symbol by pressing Command+Shift+F7.
Then for next occurrence Command+G or Command+Shift+G
On my Mac it is:
ctrl-l to find next occurrence
ctrl-shift-l to find previous occurrence
IntelliJ Keyboard Shortcuts
On Ubuntu:
Next occurrence of selected word: F3
To expand the question slightly, the method to display the next occurrence of a search term in the Find In Path pane, is to steer to it using the up/down arrows and then hit Enter.
Start by looking for all occurrence of the key (control + g)
Then use ( shift + command + g ) to find previous occurrence and ( command + g ) to find next occurrence.
For those who use IdeaVim plugin, there is another option.
Add these entries into .ideavimrc:
map <C-j> <Action>(GotoNextElementUnderCaretUsage)
map <C-k> <Action>(GotoPrevElementUnderCaretUsage)
This maps the navigation to the next/previous element under caret using ctrl+j/ctrl+k. Of course you can map it to something else, but this suggestion follows the standard navigation keys in vim.

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.