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

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.

Related

How to format code to use the specified `tabSize` with the built-in formatter?

I have the following AutoHotkey script sample, notice the code is indented by a single space:
#z::
MsgBox The Win-Z hotkey was pressed.
Gosub MySubroutine
return
MySubroutine:
Sleep 1000
return
I searched through the VS Marketplace but didn't find a usable formatter extension for AHK scripts.
I've configured "editor.tabSize": 2, is there a way to format the code to use the specified tabSize with the VSCode built-in formatter?
It looks like there is an AutoHotKey Plus extension that includes formatting that seems to adhere to the Visual Studio Code built-in formatter setting for the tab size. I set my tab size to two and performed the format shortcut using the extension (Shift + Alt + F):
It seems though that certain keywords, such as return will cling to the margin, presumably because the formatter for the extension interprets this as the standard convention for AHK (in my opinion though, I like the way it looks).
This feature request is tracked here.

Visual Studio Code C++ Formatter: indent with tabs, align with spaces?

How would I go about configuring a formatter (in my case, the Visual Studio Code C/C++ formatter) to indent with tabs, but align with spaces?
I've looked at this post and this post, but they were asked more than 5 years ago and I'm wondering if anyone has some new information to share.
I don't mind manually typing out the spaces to align, I just don't want the formatter to convert 4 spaces into a tab.
For reference, I would like my code to be formatted like this, where ---> indicates a single tab and . indicates a single space:
if (condition) {
--->aLongFunction(something).// does something
--->a(b).....................// does something else
}
If I save this code, Visual Studio Code will format it as such:
if (condition) {
--->aLongFunction(something).// does something
--->a(b)--->--->--->--->--->.// does something else
}
This is bad because if someone else wants to look at my code and they have their tab-width set to 2, it would look like this:
if (condition) {
->aLongFunction(something).// does something
->a(b)->->->->->.// does something else
}
And now it is no longer aligned, just strangely spaced out!
I think I value alignment more than I value tabs, so if it comes to it, I will simply switch to use spaces over tabs, but it would be nice if the formatter could see what I'm trying to do!

How can I configure different spacing rules inside for loops in IntelliJ Idea's code style settings?

I am currently working on a Java project, and I am finding IntelliJ Idea's code style system to be extreamly frustrating as it refuses to accept the settings that I want to give it. Specifically, I want spaces around various operators unless they're inside a for loop's header. For example, the following code should be output:
for(int x=0;x<10;++x){ // no spaces around operators when they're in a for loop's header
System.out.println(x);
}
int a = 10; //spaces around = when not in a for loop's header
int b = 50;
a = b;
if(a < b){ //an if statement is not a for loop's header
doSomething();
}
In essence, I want IntelliJ to make an exception to normal space rules when in the header of a for loop, removing these spaces. It looks absolutely disgusting to me to have what should be a dense construction filled with superfluous spaces, to the point that it is making me not want to use IntelliJ Idea at all, despite its numerous great features. THis, for example, severely diminishes the utility of its automatic refactoring ability because I need to manually go through and fix its formatting errors after every refactor.
When I look in the code style settings, the "around operators" checkboxes seem to have no mechanism for a different setting inside for loops:
How can I get IntelliJ Idea to format my code correctly?

IntelliJ IDEA: Need help to set shortcut line

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.

How to manage messages in a xcode project?

I'm a newbie in objective c.
I want to know what's the most common way to handle messages(or string format) in a xcode project.I mean, to put all the message strings or formats in one file to manage it easily.
Could anyone give me some advice??
Thanks~
Have you looked at localization options? It is usually a good idea to prepare your app or program for internationalization. The way this works is to have a file Localizable.strings where you have the exact text defined for each "text macro". The strings files (you have a version for each language) are in a very simple format:
// in en.lproj
"Hello" = "Hello, World!";
// in de.lproj
"Hello" = "Hallo, Welt!"
Just make sure in your code you consistently use this format for literal strings that are displayed anywhere in your user interface:
label.text = NSLocalizedString(#"Hello", #"Optional comment");