How to set IDEA better align parameters passed to some method? - intellij-idea

I cannot make IDEA perfectly align parameters passed to some method when I break them into new line by Enter key.
Here is visually what I need. I have a method like this.
When I break parameters into new row each, it looks like this.
Even trying to align them with Tab key does not help.
You see how ugly this is, not to say it's not easy to reach such code. And all I want is too look like this:
(Note: this one I set via Space key).
I must have been doing something wrong as I can bet this can be set in IDEA. But where?

Bring up Settings panel :
Code Style > Java > Wrapping and Braces (tab)
Enable Align when multiline option in Method declaration parameters and Method call arguments

Apart from the way suggested by #Rangi Lin, also make sure that your
Code Style > Java > Keep When Reformating > Line Breaks
in your settings is also checked. Otherwise reformatting your code could realign your method params into a single line.

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)

What is the correct way to use multiple variables in a Text element?

I can't seem to find the "correct" way to use multiple variables in a React Native Text element.
I have the users first, and the last name as separate object values and I want to show them in the same Text element.
<Text>{props.user.firstName} {props.user.lastName}</Text>
This works fine, but ESLint doesn't like it. (jsx-one-expression-per-line).
If I put them on separate lines, then I can't figure out where to put the empty space in between first and last name.
<Text>
{props.user.firstName}
{props.user.lastName}
</Text>
There's an empty space after {props.user.firstName}, but ESLint doesn't like that either (no-trailing-spaces).
So I'm asking whether there is a correct way to achieve the result that I want without changing ESLint configuration or creating a separate variable.
You're looking for template literals.
You can nest your variables like so:
<Text>`${props.user.firstName} ${props.user.lastName}`</Text>

How to Keep Velocity Ouput to a Single Line while Spanning Multiple Lines in vm File

I'm using a Velocity template to generate an e-mail. Within that e-mail, I want to create a mailto link that will look like this:
Link
I have this chunk of code that properly creates that link:
Link
That code works, but it's nearly impossible to read. I want to put some line breaks in there so that I'd have something more like this:
<a href="mailto:
#foreach(${person} in ${people})
${person.email}
#if($foreach.hasNext)
,
#end
#end
?subject=My%20Subject%20Line">Link</a>
I find that to be much easier to read, but Velocity will include all the whitespace into the output and causes the link that it produces to break.
Is there any way to format the code the way I want and tell Velocity to ignore all the whitespace throughout that segment?
Thanks!
A first option is to use comments:
<a href="mailto:#*
*##foreach(${person} in ${people})#*
*#${person.email}#*
*##if($foreach.hasNext)#*
*#,#*
*##end#*
*##end#*
*#?subject=My%20Subject%20Line">Link</a>
Another option is to add a pre-processing that will remove all indenting spaces and carriage returns.
Yet another is to do it as a post-processing.
The way to add this pre- or post- processing is dependent on the context in which you are using Velocity.

Putting the cursor in a specific place in a live template

I just wanted to know how you put a cursor in a specific place in a live template for IntelliJ
For example:
# $var$ is an insance of the $objectType$ class
assert isinstance($var$, $objectType$)$END$
What happens here is that your cursor gets dragged to $var$ in the comment string first and then to your other values inside assert. What I wanted to know is how you chose where the cursor goes first.
I've read the documentation, but this is not mentioned, although a lot of other things are.
You can arrange the order that your variables are visited in. You find the information under bullet number five in this IntelliJ help document: http://www.jetbrains.com/idea/webhelp/creating-and-editing-template-variables.html
To arrange variables in the order you want IntelliJ IDEA to switch between associated input fields, use the Move Up and Move Down buttons.
Edit
You have to update the macro definition to similar to this:
# $varComment$ is an insance of the $objectTypeComment$ class
assert isinstance($var$, $objectType$)$END$
And then you define the order and expression to something like this (I didn't have any good expression for the var and orderType for you):
Since you fill in the Skip if defined for the two comment variable they will just take the values from the var and orderType and fill it in. This will do exactly what you are looking for :-)

Reformatting to have method parameters in a new line

There are so many settings in the preferences for Code->Style->Objective-C. I'm looking for the right one to reformat this line of code
SCPropertyDefinition *test = [SCPropertyDefinition definitionWithName:#"created_at" title:#"Tweeted At" type:SCPropertyTypeLabel];
to this format
SCPropertyDefinition *test = [SCPropertyDefinition definitionWithName:#"created_at"
title:#"Tweeted At"
type:SCPropertyTypeLabel];
(the point is to have the colons indention matching)
I guess the it should be in the Wrapping and Braces Tab, but I havn't found the right setting yet.
Thanks for your ideas.
The setting you are looking for is Wrapping and Braces | Method call arguments set to Chop down if long with enabled Align by colon. Note that there are separate settings for Method parameters.
It seems like as of App Code 2017.1 (perhaps earlier too) the align by colon option is not available in Swift. You can still tell App Code to chop a long argument/parameter list: