Format only the selected block of code in IntelliJ - intellij-idea

Is it possible to format only a selected block of code. I could only either format the whole file or the whole project with IntelliJ. I use community edition 2017.2 on MacOS.

From the IntelliJ IDEA Help (Reformat File Dialog):
Highlight the block of code.
Open the Reformat File dialog:
Mac: Shift+⌥+⌘+L
Windows/Linux: Ctrl+Alt+Shift+L
Click the "Selected Text" radio button.
Click the "Run" button.
It should look something like this:

Yes; simply highlight the block of code and format it, either through the keyboard or through the menu. How it will be formatted, and what will be formatted, are driven solely by your formatting preferences.

Reformat a code fragment in a file:
In the editor, select a code fragment you want to reformat.
From the main menu, select Code | Reformat Code or press Ctrl+Alt+L.
Note. If you don't select a code fragment, IntelliJ IDEA will reformat the whole file.

Related

How to correct the code formatting settings in eclipse?

I am actively using code formatting in eclipse (right click->source->format), after that a window would pop up asking me to format the whole file or the highlighted fragment. At some point, I accidentally clicked "remember the selection" and that window never came up again.
To clarify, this is CubeIDE, based on eclipse, C/C++.
Where can I fix the settings to make this window appear again?
Found it. This is where the setting is:

IntelliJ formats the whole file even if I do not highlight any code

My IDE is IntelliJ and my laptop is Mac OS.
When I click Code -> Reformat Code, even if I am not highlighting any code, the whole file gets reformatted.
How to make it format nothing if no code is highlighted?
Thank!
The behavior is expected, see corresponding help page:
If you don't want any of the code reformatted, do not invoke the Reformat Code action.
You can always undo the misfired reformatting with Meta+Z.

How do you configure IntelliJ IDEA to place the cursor in the editor window after hitting enter on a file in the project window?

I'm big on not using the mouse, especially while writing code. I've noticed in IntelliJ IDEA 2016.1 that when I'm navigating in the project window, hitting Enter while a particular file is selected opens the file in an editor, but it doesn't place the cursor in the editor. Interestingly, if I double-click on the file in the project window, the cursor is placed in the editor.
How do I configure IntelliJ to place the cursor in the editor after opening the file via Enter from the project window?
To the best of my knowledge, I do not believe there is a way to configure what you are looking for. A search for focus in the settings didn't turn up anything.
That said, hitting Esc when in the project view will return you to the editor. So you would need to do Enter, Esc. If having to type two keys in a row bothers you, you could always record a macro (Edit > Macros) to do that key sequence and map it to a shortcut.

Focus on dialog with ideavim

I have some handy mappings set up in my ~/.ideavimrc some of which result in IntelliJ opening a new window/dialog box. For example the following line lets me type \t and it'll open IntelliJ's "jump to test" dialog box which lets me jump to an existing test or create a new test file:
:map \t :action GotoTest<CR>
This almost works great. The only issue is that when the dialog box pops up the focus is still on the editor window, not the dialog box. As a result I can't simply use the arrow keys to select my option and hit enter. Instead, I have to use the mouse. As a good code nerd, I abhor the mouse. So, how do I get the keyboard focus to change? Is this possible?
It's fixed in the master branch https://youtrack.jetbrains.com/issue/VIM-796, but the fix hasn't been released yet. You can download a CI build and help testing IdeaVim. See https://github.com/JetBrains/ideavim for more details.

In Intellij IDEA, is there a way to copy the path of the current editor tab to the clipboard?

I'm doing some writing and would like to copy the path of the current editor tab (as shown in the tooltip here) to the clipboard:
Anyone happen to know a shortcut for this?
Ctrl+Shift+C works on Windows, even if your focus is on the editor.
I assume Cmd+Shift+C will also work on a Mac.
Press Alt+Home to select current file on Navigation Bar:
Then Shift+Command+C to copy path to a file and Esc come back to editor.
I found Ctl+Shift+Alt+C can copy path with UNIX slash, not backslash.