How to format code in Xcode? [duplicate] - xcode

This question already has answers here:
Code Formatting In Xcode
(11 answers)
Closed 7 years ago.
I wonder how can I format my code to align it neatly? Does it have a feature similar to Eclipse's ctrlshiftf?

Select first the text you want to format and then press Ctrl+I.
Use Cmd+A first if you wish to format all text in the selected file.
Note: this procedure only re-indents the lines, it does not do any advanced formatting.
In XCode 12 beta:
The new key binding to re-indent is control+I.

Key combination to format all text on open file:
Cmd ⌘ A + Ctrl I

Select the block of code that you want indented.
Right-click (or, on Mac, Ctrl-click).
Structure → Re-indent

I would suggest taking a look JetBrains AppCode IDE. It has a Reformat Code command. I have come from a C# background and used Visual Studio with Jetbrains Resharper plugin, so learning AppCode has been a pleasure because many of the features in Resharper also exist in AppCode!
Theres too many features to list here but could well be worth checking out
http://www.jetbrains.com/objc/features/index.html
http://www.jetbrains.com/objc/

Related

Can't print } on Visual Studio 2017 on Italian keyboard [duplicate]

This question already has an answer here:
Recent Visual Studio update introduced shortcut used to create closing curly brace on my keyboard: how to find offending command?
(1 answer)
Closed 4 years ago.
When I press the keyboard shortcut CTRL+ALT+SHIFT+] on an Italian keyboard to add a closed curly brace, Visual Studio selects a block of my code instead of printing it.
I have already tried to reset the keyboard mapping on Visual Studio but to no avail.
Other programs works without problems. How can I fix this problem?
It is a new feature appeared in Visual Studio 2017 version 15.8.0.
It is called ExpandSelectionToContainingBlock and it is mapped to the keyboard shortcut CTRL+ALT+SHIFT+] or CTRL+ALT+SHIFT++ (For VS in Italian)
But this mapping has removed the ability, from some keyboards without the key for the closing brace (like the Italian one), to press those keys and get the, indispensable for many programming languages, close curly brace.
As far as I know there are two workarounds
Go to Tools menu and select Customize
Press the Keyboard button
Search for Edit.ExpandSelectionToContainingBlock
Press Remove
or just use the numeric keypad and press
ALT+0125
For Italian readers with the Italian version of VS, the search above at point 3 should be for Modifica.Espandiselezioneabloccocontenitore. I don't know if other languages are affected by this 'translation vice' but it is a thing to be aware of.
The problem has already been reported to MS (Thanks Albireo)
EDIT: It seems that they have fixed the problem, in version 18.5.2 there is anything assigned to the shortcut. But I am not sure if this is an effect of my previous action or if this (no shortcut) is the real default now.

Xcode environment — shortcuts and indentation utilities

(Not sure if the question belongs here, so apologies are in order)
I am heavy on sublime text and I often find Xcode to be lacking with some of the text/data processing stuff. I might have more than one question here —
'Command + /' comments code but there is no indentation. Are the any tools or utilities out there that could help me with this?
'Command + C' and 'Command + X' copy and cut lines in sublime text when there is no text selected. Is this possible in Xcode?
Moving on, is there a set of plugins or utilities for Xcode that could make it a bit more like sublime text? I understand that I need to get along with Xcode and I have, but there are somethings that Xcode doesn't do well and I am wondering if there are ways to accommodate that.
Have you considered using ST as an external editor for XCode?
How to set it up is here:
How to set an external editor in Xcode 4.2
Then you could open your files in ST and edit there getting all the features of ST natively.
If you have already tried this and it wasn't a happy experience sorry for wasting your time.

VS 2010: How do I get "next tab", "prev tab" keyboard shortcut working? [duplicate]

This question already has answers here:
Changing Ctrl + Tab behavior for moving between documents in Visual Studio
(14 answers)
Closed 9 years ago.
How do I get "next tab", "prev tab" keyboard shortcuts to work in Visual Studios 2010?
(For a more precise description of the functionality I need please see the firefox/chrome/etc and how they do their "ctrl-pgdn" and "ctrl-pgup" keyboard shortcuts).
This should be extrememly easy... and yet I can't seem to figure it out.
NOTE:
I do know that there is a "ctrl-tab" that is similar... but it only scrolls through the "most recently used list" which is different. I don't care about "the most recently used list". I just want to go to the right/left tab.
You should map the Window.NextDocumentWellTab and not View.NextTab and remove it from any other functions its assigned to. Only mapping it will not work, you also need to unmap from anything else its being used on, apparently.
This is what my keyboard configuration looks like:
Looked into this some more, and it turns you need to install the Productivity Tools. That gives you that NextDocumentWellTab function.
Under Visual Studio 2010 Professional, this keyboard shortcut goes by the name Window.PreviousDocumentWindow and Window.NextDocumentWindow.
Important Note: By default, Ctrl-PgUp and Ctrl-PgDown are assigned to Edit.ViewTop and Edit.ViewBottom respectively, so make sure to remove the existing keyboard assignment before trying out your new assignment. If you don't, the keyboard commands you enter will continue to be interpreted as the most "specific" shortcut (Edit.ViewTop or Edit.ViewBottom) since you're most likely trying this out in the Edit view!

Visual Studio 2010 shortcut to go back from definition [duplicate]

This question already has answers here:
After "Go to Definition", is there a command to return to where you came from?
(9 answers)
Closed 9 years ago.
In Visual Studio when going to definition by pressing F12, it takes you to definition. Is there any way to go back to where you came from?
This is specially annoying when you have definition within same file. If it's in another file then it's ok Ctrl+Tab take you back to previous window. But when it's in same file then have to find where you came from and go there.
Try the key combination: Ctrl + -.
As others mention, use Ctrl + -. This is the View-NavigateBackward shortcut in Visual Studio's default key mapping scheme, and can be mapped to any key combination you like from Tools->Options->Keyboard. I like Alt+← myself, to match typical web browser use.
Note that, for most five-button mice, the navigate-left button will also do this.
Ctrl + -
Ctrl -> '+' -> '-'
I searched for a long time till i found that one, and I can't stop using it since!! :)

Whats the best way to manage code snippets on Xcode?

I have fallen in love with visual studio's code snippets toolkit. Is there anything similar on Xcode?
You can also take a loot at this question which is about similar issues with XCode 3 (code templates, code completion, and more).
Xcode 4 has support for code snippets.
Of course there are. They are under "Edit -> Insert Text Macro".
Or you can simply start typing 'if<ctrl+.>' and this will be expanded into the full if statemenet.

Resources