Is there a way to remap Tab key in order to produce a block indent in Xcode (like Visual Studio)?
I added a key binding Shift+Tab to override ⌘+[ and it is working.
Even if I change ⌘+] to Tab and resolve the mapping conflicts, it doesn't work.
I'm using Xcode 6.1.1
Don't use the Key Bindings tab of Xcode's preferences. Go to the Text Editing tab. Within that tab, there's an inner tab control. Select "Indentation". There's a pop-up menu labeled Tab Key with options Indents in leading whitespace, Indents always, and Inserts tab character. It sounds like you want Indents always.
If you want to remap the standard Xcode's Cmnd+[ to Tab, you can do the following:
1) Install a program called "Karabiner".
2) Go to Preferences ~> "Misc and Uninstall"
3) In "Custom Setting" section click on the "Open private.xml" button
4) Open the file and replace its content with the following code:
<?xml version="1.0"?>
<root>
<item>
<name>Tab instead of Command+[</name>
<identifier>private.swap_tab_and_cmnd+[</identifier>
<autogen>
__KeyToKey__
KeyCode::TAB, ModifierFlag::NONE,
KeyCode::BRACKET_RIGHT, ModifierFlag::COMMAND_L | ModifierFlag::NONE
</autogen>
</item>
</root>
5) Go to Preferences ~> "Change Key" ~> click on "Reload XML" button
6) Put a tick in the checkbox which is called "Tab instead of Command+["
7) Enjoy
PS: Please note that this setting works globally on your machine, not just in Xcode. However, I am sure that google might help you to find a solution how to customize it even further, applying the changes only to Xcode.
You can indent a line of code or a selected block of code as follows:
Command-[ move code left
Command-] move code right
Related
What I really like with a text editor (or IDE) is to be able to easily remap its keyboard shortcuts to what I want, and Xcode seems to do a bad job with this.
I want to be able to switch file tabs by using option + command + arrow (left and right arrows). However, when I try to change keyboard shortcuts for the Show Previous Tab and Show Next Tab actions, the option key is not applied.
In the screenshot, you can see—through KeyCastr—how I pressed the option + command + right arrow keys and end up with command + right arrow in Xcode, the option key is missing.
Is there any solution? Note that the option key can be used on some actions, for example I can use it with the About Xcode action, but this is obviously not what I want.
I'm using Xcode 13.4.1.
Okay so I've found a solution. Not a perfect one but it works!
There is no way to use the option key in some actions because they are constrained by the Navigation in Xcode preferences.
Instead you can change the system preferences to add a new shortcut to the Xcode app.
However, when you will use those keyboard shortcuts in Xcode, you will see a weird behavior where the tab you are switching to, gets opened in a new editor.
This is due to the default navigation preferences of Xcode, change the "Optional Navigation" preference from "Uses Next Editor" to "Uses Tab".
I'm making changes to the default keybindings and getting some conflicts. Just unsure how I can unmap a keybinding that I don't need? I tried to hit delete on when selecting the shortcut in the list but to no avail.
P.S. I've tried double clicking the shortcut but no - button appears on the right.
How to delete a keybinding on Xcode ? (using version 9.3 of Xcode)
The first method is obviously the little - that sometimes appears when double-clicking a binding.
The second method is not so quick but (in my experience) just as efficient.
(Here I am assuming you've got a personalised keybinding profile already. If you don't, create one. I'll call it Personal.)
In Xcode: select the shortcut you want to remove and attribute it a random binding (even one that causes conflicts, you'll delete it in two minutes, you don't really care).
Quit Xcode.
Go to ~/Library/Developer/Xcode/UserData/KeyBindings/.
Open the file personal.idekeybindings (it's a simple XML file, any decent text editor should be able to handle it).
Find the shortcut you modified and want to delete by searching its name using command + F.
You should then find something looking like this (each dict corresponds to a modified shortcut):
<dict>
<key>Action</key>
<string>execute:</string>
<key>Alternate</key>
<string>NO</string>
<key>CommandID</key>
<string>Xcode.IDEPlaygroundEditor.CmdDefinition.Execute</string>
<key>Group</key>
<string>Editor Menu for Playground</string>
<key>GroupID</key>
<string>Xcode.IDEPegasusPlaygroundEditor.MenuDefinition.Editor</string>
<key>GroupedAlternate</key>
<string>NO</string>
<key>Keyboard Shortcut</key>
<string>^<</string>
<key>Navigation</key>
<string>NO</string>
<key>Title</key>
<string>Execute Playground</string>
</dict>
Delete this part:
<key>Keyboard Shortcut</key>
<string>^<</string>
Do that for each shortcut you want to remove and don't forget to save the file before closing it. Now open Xcode and check for the shortcut: the space for the keybinding should be empty.
When you double click a key binding, you should see an icon with a minus all the way at the right end of the text box. Simply clicking that icon removes the binding.
Xcode has two kinds of key bindings: ones you can customize within Xcode Preferences and ones you have to customize through System Preferences. The latter kind don't show a "minus" button within Xcode Preferences. To edit these:
Open System Preferences -> Keyboard -> Shortcuts
Click "App Shortcuts" then "+"
Choose "Xcode"
Put in the name and desired shortcut
Voila!
I used to use tabs for indentation and spaces for alignment.
Like so (arrows show tabs and dots show spaces).
In QtCreator you can set such coding style in standard preferences.
I can't find the way to achieve the same goal in Xcode. Could you please tell me if it is possible?
May be there is a plugin for that?
UPDATE:
Here is how it can be achieved in QtCreator:
P.S. Please, don't try to persuade me that using spaces only/tabs only is better, otherwise this question will turn into another holywar :)
Once more about what I'm trying to achieve: Indent with tabs, align with spaces. Vim Tips Wiki.
UPDATE 2: I've just submitted an Apple Radar bug-report (enhancement) rdar://22285639. Here it is on the open radar.
UPDATE 3: I received an answer from Apple. My bug is a duplicate of rdar://8165023.
In Xcode > Preferences (⌘,):
If I understand your question correctly, this should do it for you.
If you want to remap the standard Xcode's ⌘+[ to TAB, you can do the following:
Install a program called "Karabiner".
Go to Preferences ~> "Misc and Uninstall"
In "Custom Setting" section click on the "Open private.xml" button
Open the file and replace its content with the following code:
<?xml version="1.0"?>
<root>
<item>
<name>Tab instead of Command+[</name>
<identifier>private.swap_tab_and_cmnd+[</identifier>
<autogen>
__KeyToKey__
KeyCode::TAB, ModifierFlag::NONE,
KeyCode::BRACKET_RIGHT, ModifierFlag::COMMAND_L | ModifierFlag::NONE
</autogen>
</item>
</root>
Go to Preferences ~> "Change Key" ~> click on "Reload XML" button
Put a tick in the checkbox which is called "Tab instead of Command+["
Enjoy
PS: Please note that this setting works globally on your machine, not just in Xcode. However, I am sure that google might help you to find a solution how to customize it even further, applying the changes only to Xcode.
In XCode
Xcode > Preferences or use ⌘ , to open Preferences
now click on the Text Edit tab and then there is sub tab bar click on Indentation and you can change setting of the Indentation as you need
Once I start editing my code and adding for loops or if then statements my code indentation is whacked because the previous code maintains its former indentation instead of adjusting automatically.
In Visual Studio you can highlight code and select 'format selection' to fix these issues - is there anything similar in Xcode?
Before Xcode 9 (for Xcode 9 see default shortcut below)
select text
right-click
there's a "Re-indent selection" item in popup menu
In XCode 4 there is one more step:
select text
right-click
Click on "Structure"
there's a "Re-indent selection" and other options in popup menu
Or using the default shortcut:
select text
press ctrl + i
select text
press Control-I (the default keyboard shortcut)
You can do this automatically in Xcode 11
In Xcode 4.6.3, choose Editor > Structure > Re-Indent.
Shortcut: Control + I
(that's 'i', for 'indent')
This works on current selection. If no text selected, choose Edit > Select All (⌘+A) and then perform the re-indent.
(I'm more clearly restating the other answers)
These solutions re-indent text to the default xCode behaviors. To change these behaviors, go to xCode (v.4) > Preferences > Text Editing. Then to Indentation Tab.
Xcode 9.2:
You can select text and press ctrl + i to re-indent code.
You can do it in different ways, but these two are the easiest
select text ( ⌘ +a) :
Using shortcut -> (control)^ + i
Click on "Editor" -> Click on "Structure" -> Click on "Re-indent"
Sometimes setting Xcode global preferences is not enough for ^ + i to do its job accordingly. The reason is that project settings override global ones. You can set indentations for a concrete project or even a file.
Select project (or file) in the Navigation Pane. Then in File Inspector go to Text Settings section and set desired number of tabs or spaces for indents.
To quickly re-indent the whole file:
⌘+a
⌘+x
⌘+v
Edit: No longer working in Xcode 11
You can try my extension Swimat
https://github.com/Jintin/Swimat
It support format on selection.
Simple install by brew cask install swimat
My textmate suddenly stopped recognizing comments in code and the shortcut for commenting out code (Command + /).
I have found Comments in the Bundle Editor for HTML, but it doesn't look like I can set an activation key for it or anything.
Does anyone have any experience with this part of TextMate?
cheers!
Maybe it went out of scope? Doesn't matter what caused it, it's easy enough to fix.
Open your Bundle Editor
ctrl-option-cmd-B
Make sure that the Menu button at the
top left-hand side of the Bundle
Editor displays Show All
If it doesn't then click the up/down
arrow and change it so that does
Scroll down until you find the
Source bundle
Click the arrow to the left of
Source to display the Bundle contents
looking at the Source Bundle items
with green "C"s next to them, find the item
called Comment Line/Selection
Click Comment Line/Selection
In the upper right-hand corner of the
Bundle Editor, click the Settings
button
Next to Activation, select the menu
item Key Equivalent
Whatever is in the text box to the
right, replace it with cmd-/ (with
your cursor in the text field, press
the keys "cmd" and then "forward
slash"
Verify that the item Scope Selector
text area is blank--nothing should be
in there
Exit the Bundle Editor, Restart
TextMate, open a new editor window
(cmd-N) then enter cmd-/ to verify
that it's working
This command is not limited by scope so it will work in any context/environment/language, but because it is not limited by scope it can be overridden by a Bundle-specific comment command (e.g., a comment command in the HTML Bundle, so, if after you've followed those steps, it's still not working, you just need to find that Bundle-specific comment command and either fix it (using the steps above as a template) or then use the steps above as a template) or deleting it.
While you're at it, you might as well fix the command in your HTML Bundle:
from your Bundle Editor, scroll down to the HTML Bundle then click on the Comment item (you said in your Q, you had located it). Click the Settings button on the upper right-hand corner, and verify that Activation is Key Equivalent and cmd-/ is in the adjacent text box. Next verify that Scope Selector is text.html