How to change Code style for adding space around parameter within an IntelliJ environment? - intellij-idea

I accidentally changed something within the code style in my PhpStorm. Now, when I press Ctrl + Shift + F for formatting, a space is placed in front and after parameters in a method call within a function.
How can I change this back?

Go to Editor > PHP > Spaces > Within, see if "Function declaration parantheses" or "Function call parantheses" are checked.

In tab "Spaces", option "Within", desactive "Method declaration parentheses".

Related

Wrap an existing variable to be the argument to a newly-typed method call in IntelliJ code editor

I have this:
this.label = label;
I want this:
this.label = Objects.requireNonNull( label );
Is there a shortcut way to edit such a line rather than me typing in the Objects.requireNonNull() followed by cut/paste or dragging the variable to inside the parentheses?
I can imagine selecting the variable (label in this example), then pressing some keystroke that lets me type the method call, and upon hitting Return puts that var within the parens.
Surround live template
You can create a surround live template.
Surround templates wrap a block of the selected code with the text specified by the user. For example, T expands into a pair of tags, for which you can specify a name. You can also select a block of code, then press Ctrl+Alt+J to open the Select Template popup and select the T template to wrap the selection with a pair of tags.
Here is an example of creating your desired Objects.requireNonNull, here with abbreviated name ornn.
To invoke your live template:
Select the text you want to surround.
Press the keystroke currently designated for live templates.
You discover that needed keystroke by looking at Preferences/Settings > Keymap > Other > Surround with Live Template….
That shortcut would be…
macOS: Option + Command + J
Windows: Control + Alt + J
Structural Search
Another option would be to configure Structural Search and Replace inspection with the quick fix, then apply it via the Alt+Enter on the matched code.

Intellij Idea - complete next parameter shortcut

Example:
Author author = new Author("Jack", "Daniels");
In Exlipce when filled "Jack" and pressed "enter" - it automatically went to second parameter and let me fill second one. In Intellij I always have to click with mouse, or use arrow keys.
Is there a shortcut in Intellij to make it quicker? I can't find one myself.
Since IntelliJ 2018.2
You can now jump outside the closing bracket or quote with Tab.
(from: https://blog.jetbrains.com/idea/2018/07/intellij-idea-2018-2-macbook-touch-bar-java-11-breakpoint-intentions-spring-boot-version-control-and-more/)
Basically it means if you have:
Author author = new Author("Jack<cursor>");
And you press Tab, the cursor is placed like this:
Author author = new Author("Jack"<cursor>);
Note: it doesn't matter where the cursor is initially, as long as you are somewhere inside the quotes when you press Tab the cursor is moved outside and placed behind it. If you want to enter the next parameter you have to manually type the comma and String.
The option can be found under: Settings -> Editor -> General -> Smart Keys and is called Jump outside closing bracket/quote with Tab
There are some other useful options there as well like insert pair quote and insert pair brackets.
If you want to go more advanced you can have a look into Live Templates.

Is there a shortcut to go to the beginning/end of a file in IntelliJ?

I often need to get quickly to the very beginning or very end of a file in the IntelliJ editor. Is there a shortcut key or button that allows me to do this quickly?
I am running on Windows, if that matters.
Beginning of File: Fn + ⌘ + ←
End of File: Fn + ⌘ + →
Note: This answer was posted prior to windows specificity. Leaving it here to include MacOS alternative.
On Windows, you can use Ctrl+Home and Ctrl+End to go to the beginning and end of a file respectively.
The action is called Move caret to Page Top/Bottom, default shortcuts would depend on the OS/Keymap and can be checked here:
On Windows these are Ctrl+Page Up and Ctrl+Page Down.
To find what keyboard strokes are already defined for this, go to Preferences->Keymap and search for text start for jumping to the beginning of the file and text end for jumping to the end of the file. You'll get something that looks like this:
The right column tells you what keystrokes have been mapped to these functions. Feel free to change them to something that you find more intuitive by double clicking on the right column and following the instructions on the pop-ups.
Under preferences -> Keymap, a shortcut for Scroll to Bottomand Scroll to Top can be set.
By default, they are not assigned.
By default in windows the shortcut is
ctrl+end
You can customize the shortcut. To use only end button as shortcut go to Settings -> Keymap -> Editor action -> move caret to text end
Right click on move caret to text end and update shortcut to end
On a Mac, these following keys:
to start of the file:
option + command + [
to end of the file:
option + command + ]
After spending minutes to search on the web, i don't find the answer for just using cmd + up or down. If you are the same, as a quick workaround, you can cmd + a to select all text and press up or down to move it.

How to change key to 'accept' intellisense 'offer' for VB.Net in Visual Studio 2015 (update 3)

When I'm coding in VB.Net in VS2015 I would like to use CTRL+SPACE to select Intellisense proposal when coding. Currently I have to use SHIFT+SPACE and I see no way to change it.
In the preceeding example screenshot it is visible that I have 3 potential options to autocomplete. I can select any of them with key up/down but in order to select the proposal I have following options:
Press 'SHIFT+SPACE' - this will accept the proposal and position the
carret right after the word enabling me to press '(' or whatever else
I want
Press 'SPACE' - this will accept the proposal but it will also
add a white space at the end which is ok for properties/fields but
not good for methods
Press '(' - this will accept the proposal but it
will also add a '(' character at thend which is ok for functions/sub
but not good for properies/fields
Press 'CTRL+SPACE' - this actually does not do anything :(, CTRL on its own makes the Intellisense menu gray-out
In the key configuration window I found the Edit.CompleteWord command:
However this command already has CTRL+SPACE assigned it but it simply does not work. In addition SHIFT+SPACE is not mentioned as one of the keybindings.
Note:
VS2015 does have a flag 'Toggle Completion Mode' but I actually see no difference if this option is checked or not.
you can Use Tab and this will accept the proposal and position the current right after Tab Use space it well show You next Complete Word .

Returning to usage's location after Intellij IDEA "Create on Usage" intention action

Suppose I type a Java method call with an argument that I intend to make into a field:
knownObject.knownMethod(newField);
At this point, newField is highlighted as compilation error. I can press Alt+Enter and select "Create Filed 'newField'" from the menu.
That brings me up to the beginning of the class file where other fields are defined.
I can press Enter to confirm the new field's type.
Now I'd like to go back to my knownMethod() call and continue coding. How do I do that?
Bonus question: in the above situation, Ctrl+Shift+Backspace may help because I just edited the the knownMethod() call. What if I decide to first type in multiple arguments to the method? How do I get back to the argument I've just created a field for in that case?
For getting back to a previous caret location the Navigate > Back menu item usually works (CtrlAltLeft Arrow on Windows). Another option may be to use Edit > Find > Find Usages on the field (enable the Skip results tab with one usage checkbox setting)