Assume I have the following..
public void DoSomething()
{
var foo = 1 + bar;
}
If I type var b ReSharper will recommend bar for the variable name. The problem then is that I need to press the down key and enter to select the recommendation. Is there a quicker way to select the top option?
I'd rather avoid having to create an AutoHotKey shortcut...
** UPDATE **
My primary concern is not having my hands leave the home row as I'm a heavy Viemu user.
Just press Ctrl+Space, and the only option on the list (that is, "bar") will be automatically committed.
The other answer is perfectly valid as well
Actually as soon as you're in this caret position:
var foo = 1 + bar|
you can Alt+Enter to see ReSharper suggest different declaration option where "Create local variable 'bar'" will be the first option.
Place you cursor on bar, press ALT+Enter and select "create local variable 'bar'" by pressing 'Enter', fill out the type and you're done. So in effect it's: mouse click, ALT+Enter, Enter, v, a, r, TAB
No Arrow key involved unless you don't have a mouse.
Related
Assuming data is a normal Kotlin data class, I want to surround a block with a with construct, so that
myFun(data.start, data.end, data.name)
becomes
with(data) { myFun(start, end, name) }
Could that be done with an IntelliJ refactoring (ideally with a keyboard shortcut). I couldn't find any suitable option in IntelliJ 2022.3
I don't know of such a refactoring, or any way to do this in one step.
However, I would usually just extract a function from it:
extract a function from this expression with Ctrl + Alt + M
(sometimes) if data was captured in the function instead of automatically passed as param, I would make it a param by using Ctrl + Alt + P on it. This might happen if data is a property that's available wherever your new function ends up.
turn the param into a receiver by using Alt + Enter on the data param declaration and selecting the quick action Convert parameter to receiver
Now you should have:
data.myFun2() // call site
fun TypeOfData.myFun2() = myFun(start, end, name)
Then you can leave things this way (I personally like it like that), but if you want your end result to look like in your question, you can do a couple more steps:
manually change data.myFun2() to with(data) { myFun2() } (simpler because you have only one occurrence to change now)
inline the call to myFun2() with Ctrl + Alt + N
But the whole sequence might feel overkill if you want to go to this result.
Let's say | is a cursor pointer. What I want to do is to get out from parenthesis once I finish typing paremeters. In step by step explanation:
// 1: type function name
void function|
// 2: openening paren automatically generate closing paren for convenience
void function(|)
// 3: type paremeters...
void function(42|)
// 4: ...and get out of parenthesis!
void function(42)|
Usually I use right arrow to do that, but using arrows are not so convenient, and I wonder if there's any shortcut for this. What I'm curious at is IntelliJ's, but it would be very nice if you can tell me shortcut of any other Jetbrain IDE or Visual Studio, etc.
I think you are looking for Ctrl + Shift + Enter (on Windows). The Action name is Complete Current Statement
On Mac if you want to know the shortcut invoke Command + Shift + A (Find Action) then type Complete Current Statement it will show you the shortcut for the action as well
The shortcut you're looking for, on most keyboards, is shift+0 -- this won't work on the keypad, only the main numbers at the top of the keyboard. Technically this isn't a shortcut, you're actually typing the close parenthesis, but IntelliJ is smart enough not to double up on them so it's as good as a shortcut in this case.
Another setting that I find convenient to use is this option.
Settings - Smart Keys - Jump outside closing bracket/quote with Tab
Is there any intellij idea shortcut to select a token in a statement?
For example, consider this:
cell.setCellValue((profileInfo.get("startTimeOfCrawl")!=null)?profileInfo.get("startTimeOfCrawl"):"");
Currently, if my cursor is on the first character of the above statement(i.e. at beginning of c of cell, if I have to select profileInfo, then I will have to use my mouse and double click on profileInfo to select that.
Another workaround I found was to use arrow keys to get cursor to profileInfo
Then use ctrl+shift+right-arrow keys to select till the end(i.e. till o) of profileInfo
This is good when my cursor is placed at beginning of profileInfo(or even end in which case we can use left-arrow key).
But if my cursor is placed somewhere in between of profileInfo then I will have to use ctrl+right (or ctrl+left) to get the cursor to either beginning or end of this token. Then I Will have to use ctrl+shift+right-arrow (or left-arrow as the case may be).
(Switching from keyboard to mouse breaks the continuity, hence looking for keyboard shortcuts.)
Is there a better shortcut to do above in 1 step?
PS: Solution to above will be very useful when making string replacements.
Use Edit | Extend Selection (Ctrl-W in the default keymaps, Alt-Up in the Mac OS 10.5+ keymap). You can press it multiple times to extend the selection to larger enclosing syntax constructs.
I can't think of a 1-step process of doing this but try using the alt to traverse via arrow keys, it will traverse it per "word" instead of per character.
You can also use alt+shift+ arrow keys to select per word.
There is an useful functionality in IDEA that lets you create a field, and it appears in the little light-bulb when you highlight the non-created variable.
However, I can't find the short-cut, searched for "create field" in the settings but no luck.
Anyone knows?.
Control + Alt + F on a literal will give you the option to extract the value into a field.
Use Alt-Enter to access the lightbulb menu and then use the arrow keys to select the necessary option. There is no possibility to assign shortcuts to individual quickfixes (there are too many of them).
On MacOS, its option-command+F.
Its much faster than Option-Enter, then you need some brain cycle to select create field in the down down menu
This is my code snippet,
reg = selectRegion("Selected a region")
reg.keyDown(KEY_CTRL)
reg.keyUp()
My objective is to select some lines, as we do it by pressing CTRL and then scrolling down, but it throws
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Invalid key code
It's obvious that I have done something wrong, Could any one help me out with this??
The documentation on special keys says to use CTRL with keyDown(). KEY_CTRL is used with type() or other cases where you want to add the modifier key as a mask. (And that's actually deprecated and should be KeyModifier.CTRL now, instead.)
For example:
reg.keyDown(CTRL)
... some code that scrolls ...
reg.keyUp(CTRL)
Or to press the "down" key twice while holding control:
reg.type(Key.DOWN + Key.DOWN, KeyModifier.CTRL);
(As a side-note, it's generally shift that's used as the modifier key for creating a selection and not control.)