IntelliJ IDEA: Need help to set shortcut line - intellij-idea

I am new to coding ... and i am using IntelliJ idea ... my question is ...
i want to make some shortcut for lines... like ...
System.out.println(); or
Scanner input = new Scanner (System.in); ..
and if i type like sop it will print ..system.out.println(); ... as those type of lines i have to use almost every code ... so it will be good if i can make shortcuts for those. is it possible to make this kinda shortcut in Intellij???

It's called Live Templates and there are a couple of them predefined. You can easily define your own.
The first one for System.out.println() is used by printing sout and then Tab.
A couple of the predefined ones can be found in Help -> Default Keymap Reference:
As you can see pressing Ctrl + J will bring up a list of available Live Templates.

Related

VIM equivalent of IntelliJ's expand/shrink selection?

How would one achieve the same result. I believe the keybinding for macOS Intellij is op+up/down and on windows it is alt+w/d.
Essentially the function highlights the current word, then, with successive presses, expands out to the full string/line/area in-between parenthesis/further out to the next set of parenthesis. Very useful for developing in LISP.
The closest I've gotten is this: https://vi.stackexchange.com/a/19028
Try this plug in: https://github.com/terryma/vim-expand-region
It expands selections based on Vim’s text objects.
Well this may seem comfortable but does not correspondent with the internal logic of vim itself.
See, in vim everything you enter is like a sentence. va{ for example: there is a verb v -> visually select and an object (or movement) { -> paragraph. In this case there is also a modifier a around. You can exchange stuff in this sentence and it will still work vaw, dil, cB and so on. The power of vim is greatly based on that concept.
Of course you can write a function that does vaw first, then S-v and lastly va{ but that will only work with visual selection. It will not work with c or d or anything. So I will recommend to get used to use different keys for different actions.
The visual selection is mostly not needed anyway. Change a paragraph? directly use ca} and so on.
I have found that VI/VA + WOBO (as many times as you need to expand) works similarly. Not as fast but its the same concept and you can even expand/shrink asymmetrically based on your WO's and BO's (Or OW's and OB's depending on how you look at it)

How to get output of Kotlin IntelliJ scratch file?

A script as simple as
println("a")
doesn't produce any output in the Scratch output window. I expect an a to appear in the output window.
I'm using IntelliJ 2019.1.2 CE.
EDIT: Information regarding the expected functionality
According to a question I had asked: IntelliJ Ultimate Kotlin Script REPL skips first printed lines - Scratch Output cut off
It seems to be the case that the REPL wants to output per line, and will only overflow into the bottom area after a certain line length is reached.
In the question I state that I generally add some initial padding so that it always flows into the lower area with something similar to:
repeat(10) { println("BLANK ") }
END EDIT
You have to make sure that Interactive Mode is turned off at the top of the scratch window
This will cause prints to be put into the Scratch Output window.
Be warned, atleast in the version I have of IntelliJ ultimate 2019.1.3, the first 5-9 lines generally dont print so I do something like:
repeat(9) { println("blank") }
If you've defined everything inside of a function, the script won't execute the function automatically - you'll need to explicitly call the function.
You can create your own print, like this:
fun <T> myPrint(x: T) : T = x
then calling e.g.:
myPrint(5)
should show 5 in the result window.

How can I automatically format C# line indentations like VB.NET

When I write something in VB.NET, the IDE automatically formats my line indents perfectly, I don't have to use the tab key at anytime.
In C#, when I needed to edit a line of code, and I perhaps wrecked up the indentation like this...
void MyVoid()
{
if (1==1)
{
int iThis = 5; //line with ugly indentation
}
}
..., and I have to correct the indentation manually or use Ctrl AKF to fix it.
In VB.NET, the IDE would fix it automatically when I skip to any other line.
How can I make this as easy as it is in VB.NET?
You can use my (commercial) Continuous Formatting extension that formats the code as you type.
Power Commands has an option to automatically format the document when you save. There's also a lighter-weight extension titled Format document on Save that should do the same.

Shortcut to get out of parenthesis in IntelliJ (or possibly other IDE as well)

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

Intellij IDEA generate for-each/for keyboard shortcut

Is there a keyboard shortcut generating a foreach and also for loop?
you can use 'live templates' to generate several types of code snippets, loop iteration is done by following -
iter Iterate (for each..in)
itin Iterate (for..in)
itli Iterate over a List
itar Iterate elements of array
ritar Iterate elements of array in reverse order
There are probably many more, just lookup 'Live Templates' in help documentation.
Pressing Ctrl+J opens the list of live templates within your code context. Then type 'itin'.
Aditionally to other answers, you don't even have to use Ctrl + J (but nice for checking what are your possibilities..) Just start type and press Enter:
Foreach:
type "iter" then press Enter.
For loop:
type "fori" then press Enter.
Idea will recognize the context and suggest the most likely var to iter through, if you like the given options, just press Enters!
Of course, have a look in the help at the default keymap references. Type one of the following and hit "tab":
iter Iteration according to Java SDK 1.5 style
inst Check object type with instanceof and downcast it
itco Iterate elements of java.util.Collection
itit Iterate elements of java.util.Iterator
itli Iterate elements of java.util.List
Create for loop from an existing list statement:
Highlight the list
Cmd+Alt+J or Ctrl+Alt+J
Choose Iterate Iterable from the dropdown (i)
https://www.jetbrains.com/phpstorm/help/creating-code-constructs-using-surround-templates.html
You can also use Surround with!
Mac : Command+Option+T
Windows : Ctrl+Alt+T
https://www.jetbrains.com/phpstorm/webhelp/surrounding-blocks-of-code-with-language-constructs.html
There is also plenty of live templates in the internet ! you can just google it.
You can use Postfix Completion too. Press Ctrl + Alt + S to open the Settings.
For example:
int[] list = {1, 2, 3};
list.for -> for(int i : list) {}
You can create your own live template, for example, I created this for iterating over an array: