Is there any shortcut key to align code content in Xcode? - objective-c

Is there any shortcut key to align code in Xcode? Just like Ctrl+K+D in Visual Studio?

⌃ + i (ctrl + i) is the shortcut key equivalent to Editor > Structure > Re-Indent ( in Xcode 6.4)
This will re-indent the line the cursor is on if no text is selected, or it will re-indent your selection.

1.) Select the text you want to align,
then
2.) press ctrl(^) + I.

If you want more than just indentation Xcode does not yet offer built in code formatting but you can use external tools like Uncrustify to apply a consistent code style.
I described how I last set this up here: http://blog.carbonfive.com/2009/08/07/code-formatting-in-xcode/

Turn on automatic code indentation, then Command+X, Command+V. In other words, cut and paste in place. If your syntax is correct Xcode shouldn't have trouble formatting it (unless you're missing newlines).

There's a menu command:
Edit > Format > Re-Indent
I don't think there's a shortcut on it by default, but you can easily create one in the Key Bindings tab in the Xcode Preferences.

Use default, "COMMAND [" and "COMMAND ]"
Simple!

as #McGordon says, Control + i works on indenting.
(As of Xcode 4.1) its there in the menu at
Editor --> Structure --> Re-Indent

Select the text you want to Align And then press Control(ctrl)+I.

The defaults way Xcode is set up is to use Control + i (also known as ⌃ + i)
If you want to change this then:
Open xcode preferences
Go to Keybindings
Search for "Indent"
Edit and change it to whatever you like.

=> Select All Code by (command + A)
=> Press (control + ]) for indent.

Related

IntelliJ IDEA: Can't type { and [

So I have a problem where in IntelliJ IDEA I can't type In
<br>{ --(Alt Gr + B or Ctrl + Alt + B)
and
[ --(Alt Gr + F or Ctrl + Alt + F)
<br>
I did try to edit shortcuts but there are no shortcuts that match mentiond ones
And when I try using SquareBrackets I get a message a little bit like this: "Cannot perform refactoring. Caret should be positioned at the name of local variable or expression to be refactored"
How can I fix this problem?
It worked for me by going to Ctrl+Shift+A (actions) -> Registry... and then disabling "actionSystem.force.alt.gr"
Worked for me:
While focus is on PyCharm then Ctrl+Shift+A (actions) -> Registry... and then enabling "actionSystem.force.alt.gr"
An other solution (not related to Jetbrain's suite).
This solution suits you if :
The problem is sporadic (occurring at irregular intervals and eventually disappear)
AltGr combinations seems not works on some other windows app
In this case this is a well known bug in Windows, just close all your RDP sessions and the AltGr will start acts as it should.
Guys I found a solution to BOTH of the problems So here are the solutions:
This applies for:
KeyBoards Without [ and { keys (I just English-UK ones have those keys)
and IntelliJ IDEA Deafult KeyMap (May work for some others)
For the "Can't type [ in IntelliJ IDEA":
1.Press Ctrl + Alt + S ,Alt Gr + S or Goto: File > Settings > KeyMap
2.Extend Folder:Main Menu, then folder Refactor and THEN folder Extract
3.Right-Click onto Field...
4.In the pop-up menu Click on Remove Ctrl + Alt + F
For the "Can't type { in IntelliJ IDEA":
1.Press Ctrl + Alt + S ,Alt Gr + S or Goto: File > Settings > KeyMap
2.Extend Folder:Main Menu, then folder Navigate and THEN folder Bookmarks
3.Right-Click onto Implementation(s)
4.In the pop-up menu Click on Remove Ctrl + Alt + B
Hope that helped You :D
There are related issues on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-177327, https://youtrack.jetbrains.com/issue/IDEA-91975
Problem should be fixed in IDEA 2018.3.
By the way, you could try to add "actionSystem.force.alt.gr=true" option using "Help | Edit Custom Properties"
win10
Pycharm 2018.1.3
ctrl+shift+A
Registry
ENABLE "actionSystem.force.alt.gr", which was disabled initially
SOLVED for me!
In my case it was caused by LaTeX plugin for IntelliJ IDEA. After its installation the 'Toggle Star' option key was set 'alt+shift+8' which coincides with { of my keyboard. Hence the solution is analogous to your own answer:
1) Open Keymap (double-shift and type keymap)
2) Expand: Main menu > LaTex
3) Right-click 'Toggle Star' and remove the mapping.
4) Apply + Ok
If your problem is happening all over Windows and you have two different active Keyboard Layouts, for example English and German, this is what worked for me (don't ask me why):
switch to english (win + space), and type a { there (shift + Key to the right of P).
now switch back to your original language and it should be working again
I had the same problem but with PyCharm.
Unfortunately none of the mentioned answers worked for me. I am on an MacBook using a German layout keyboard. The Problem for me was a changed default setting in the terminal settings. I had to disable "Use Option as Meta Key". On a German Keyboard many "special" characters like [],#, {}, etc. are alt(option) Key-Combinations. I think this is true for other european keyboards as well. (I know for the suisse and the danisch for sure)
In my case, another application was using Alt Gr + 7 && Alt Gr + 8 shortcuts for other processes. So if previous solutions are not helpful, make sure that shortcut is not being used by another program.

XCode9 how to get right click > Structure > Reindent back?

I see that XCode9 is messing up the indentation of my code. Before this could be fixed with right click > structure > re-indent. How do I get equivalent behavior in XCode9?
This won't get the Structure->Re-Indent context menu back but might be useful.
There's a ^I (ctrl + i) shortcut for that, which re-indents selection.
If you don't want to use Key Bindings, the command is available using the menu:
Editor->Structure->Re-Indent
Note that default combination looks very much alike ^| (ctrl + shift + \) on Key Binding pane . I've been banging this combo for some time and even redefined the shortcut to ctrl+shift+\ before figuring out the correct one:

How to fold try/catch, switch, for, while and if statements in IntelliJ Idea?

IntelliJ Idea fold if and other statements in JavaScript, but not in Java. How can I get this feature? Maybe you know some plugin or settings?
I don't think that it's possible from Code > Folding or using the icons from the left bar (collapse/expand), but you can do it in a harder way: manually.
E.g.:
select the try block
Code > Folding > Fold Selection / Remove Section ( Ctrl + Period, where Period is the .)
you'll see ... instead of that block
now that block also has the icons for collapse/expand on the left bar
In Android Studio, in order to fold a try/catch structure -
In the editor window, select the left brace after try
Type on keyboard CTRL + Shift + .
Now the complete try { .. } block will be folded.
If I want to reduce a try / catch section, it doesn't work for me on Intellij CI 2016, under Ubuntu 16.04 OS.
Even with shortcut or using menus.
Using menus Code > Folding > Fold Selection / Remove Section ( Ctrl + Period, where Period is the .), it'll close the entire function where the try/catch block is.
It doesn't work either if I use shortcut Ctrl+ Shift + .
Seems to be a conflict with other shortcut existing on the OS I'm running onto.

How to auto-indent code in the Atom editor?

How do you auto-indent your code in the Atom editor? In other editors you can usually select some code and auto-indent it.
Is there a keyboard shortcut as well?
I found the option in the menu, under Edit > Lines > Auto Indent. It doesn't seem to have a default keymap bound.
You could try to add a key mapping (Atom > Open Your Keymap [on Windows: File > Settings > Keybindings > "your keymap file"]) like this one:
'atom-text-editor':
'cmd-alt-l': 'editor:auto-indent'
It worked for me :)
For Windows:
'atom-text-editor':
'ctrl-alt-l': 'editor:auto-indent'
The accepted answer works, but you have to do a "Select All" first -- every time -- and I'm way too lazy for that.
And it turns out, it's not super trivial -- I figured I'd post this here in an attempt to save like-minded individuals the 30 minutes it takes to track all this down. -- Also note: this approach restores the original selection when it's done (and it happens so fast, you don't even notice the selection was ever changed).
1.) First, add a custom command to your init script (File->Open Your Init Script, then paste this at the bottom):
atom.commands.add 'atom-text-editor', 'custom:reformat', ->
editor = atom.workspace.getActiveTextEditor();
oldRanges = editor.getSelectedBufferRanges();
editor.selectAll();
atom.commands.dispatch(atom.views.getView(editor), 'editor:auto-indent')
editor.setSelectedBufferRanges(oldRanges);
2.) Bind "custom:reformat" to a key (File->Open Your Keymap, then paste this at the bottom):
'atom-text-editor':
'ctrl-alt-d': 'custom:reformat'
3.) Restart Atom (the init.coffee script only runs when atom is first launched).
Package auto-indent exists to apply auto-indent to entire file with this shortcuts :
ctrl+shift+i
or
cmd+shift+i
Package url : https://atom.io/packages/auto-indent
I prefer using atom-beautify, CTRL+ALT+B (in linux, may be in windows also) handles better al kind of formats and it is also customizable per file format.
more details here: https://atom.io/packages/atom-beautify
You can just quickly open up the command palette and do it there
Cmd + Shift + p and search for Editor: Auto Indent:
This works for me:
'atom-workspace atom-text-editor':
'ctrl-alt-a': 'editor:auto-indent'
You have to select all with ctrl-a first.
This is the best help that I found:
https://atom.io/packages/atom-beautify
This package can be installed in Atom and then CTRL+ALT+B solve the problem.
On Linux
(tested in Ununtu KDE)
There is the option in the menu, under Edit > Lines > Auto Indent or press Cmd + Shift + p, search for Editor: Auto Indent by entering just "ai"
Note: In KDE ctrl-alt-l is already globally set for "lock screen" so better use ctrl-alt-i instead.
You can add a key mapping in Atom:
Cmd + Shift + p, search for "Settings View: Show Keybindings"
click on "your keymap file"
Add a section there like this one:
'atom-text-editor':
'ctrl-alt-i': 'editor:auto-indent'
If the indention is not working, it can be a reason, that the file-ending is not recognized by Atom. Add the support for your language then, for example for "Lua" install the package "language-lua".
If a File is not recognized for your language:
open the ~/.atom/config.cson file (by CTRL+SHIFT+p: type ``open config'')
add/edit a customFileTypes section under core for example like the following:
core:
customFileTypes:
"source.lua": [
"conf"
]
"text.html.php": [
"thtml"
]
(You find the languages scope names ("source.lua", "text.html.php"...) in the language package settings see here)
If you have troubles with hotkeys, try to open Key Binding Resolver Window with Cmd + .. It will show you keys you're pressing in the realtime.
For example, Cmd + Shift + ' is actually Cmd + "
You could also try to add a key mapping witch auto select all the code in file and indent it:
'atom-text-editor':
'ctrl-alt-l': 'auto-indent:apply'
I was working on some groovy code, which doesn't auto-format on save. What I did was right-click on the code pane, then chose ESLint Fix. That fixed my indents.
If you are used to the Eclipse IDE or the Netbeans, you can use the package eclipse-keybindings (https://atom.io/packages/eclipse-keybindings):
This Atom package provides Eclipse IDE key mappings for Atom. Currently, the Eclipse shortcuts are directly mapped to existing Atom commands.
To format all lines from a file, just use: Ctrl+Shift+F.
Ctrl+Shift+i worked for me in PHP under Windows ... but some files did not react. Not being the brightest it took me a while to work out that it was the include files that were the problem. If you are using echo(' ... PHP ...') then the PHP does not get re-formatted. To get over this, create a temporary PHP file, say t.php, copy the PHP part into that, reindent it (Ctrl+Shift+i ... did I mention that?) and then copy the newly reformatted PHP back into the original file. Whilst this is a pain, it does give you correctly formatted PHP.

How do I use a shortcut to comment out code automatically in Textmate?

Is there a shortcut to highlight and comment code in textmate, rather than putting in the comments manually?
If you have the Source bundle installed:
⌘/
If you don't, go to TextMate > Preferences > Bundles and check Source.
⌘/
comment/uncomment selection
shift + ⌘ + 7 or instead 7 the key with the slash "/"