Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode indentation key bindings

Is there a way to get Xcode 4 to indent text so that pressing tab on selected text would indent it, shift + tab would unindent like in many editors?

The default ⌘] and ⌘[ do not seem to work, probably because I have a Finnish keyboard layout. Pressing the key combination for [ (alt + 8) and additionally holding down does not indent.

In Xcode preferences I found "Key Bindings" and "Shift Right", "Shift Left", but it does not seem to understand shift + tab. If I try to press shift + tab I get ⇧⌘⇤.

enter image description here

like image 572
Bemmu Avatar asked Jun 17 '11 16:06

Bemmu


People also ask

How do you indent multiple lines of code?

How do you indent many lines of code? If you prefer using [spacebar] to indent your code rather than using [tab], you can select multiple lines by holding the [alt] key and clicking on the beginning of each line you want to indent. Then, you can press [spacebar] and all the selected lines will be affected.


2 Answers

As a workaround if you can't enter shift-tab, you could find the key binding (stored at ~/Library/Developer/Xcode/UserData/KeyBindings and modify it directly. It's XML so you should be able to do this without too much trouble.

like image 96
jtbandes Avatar answered Oct 12 '22 23:10

jtbandes


Setting the Tab binding for Shift Right did not work for me either even when remapping "Insert Tab" to something else (seems hardcoded/bug). However I did get Alt + Tab and Shift + Alt + Tab binding working (with the Finnish Keyboard layout, didn't test extended or sami). I still had to remap "Insert Tab without Extra Action" from Alt + Tab to Alt + Ctrl + Tab, you could avoid this by using Ctrl instead of Alt for shifting.

Here is the xml file for it.

cd ~/Library/Developer/Xcode/UserData/KeyBindings

vi Default.idekeybindings (probably empty plist, if not extend appropriately)

Paste:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Menu Key Bindings</key>
    <dict>
        <key>Key Bindings</key>
        <array>
            <dict>
                <key>Action</key>
                <string>shiftRight:</string>
                <key>Alternate</key>
                <string>NO</string>
                <key>CommandID</key>
                <string>Xcode.IDESourceEditor.CmdDefinition.ShiftRight</string>
                <key>Group</key>
                <string>Editor Menu for Source Code</string>
                <key>GroupID</key>
                <string>Xcode.IDESourceEditor.MenuDefinition.Editor</string>
                <key>GroupedAlternate</key>
                <string>NO</string>
                <key>Keyboard Shortcut</key>
                <string>~   </string>
                <key>Navigation</key>
                <string>NO</string>
                <key>Parent Title</key>
                <string>Structure</string>
                <key>Title</key>
                <string>Shift Right</string>
            </dict>
            <dict>
                <key>Action</key>
                <string>shiftLeft:</string>
                <key>Alternate</key>
                <string>NO</string>
                <key>CommandID</key>
                <string>Xcode.IDESourceEditor.CmdDefinition.ShiftLeft</string>
                <key>Group</key>
                <string>Editor Menu for Source Code</string>
                <key>GroupID</key>
                <string>Xcode.IDESourceEditor.MenuDefinition.Editor</string>
                <key>GroupedAlternate</key>
                <string>NO</string>
                <key>Keyboard Shortcut</key>
                <string>~$</string>
                <key>Navigation</key>
                <string>NO</string>
                <key>Parent Title</key>
                <string>Structure</string>
                <key>Title</key>
                <string>Shift Left</string>
            </dict>
        </array>
        <key>Version</key>
        <integer>3</integer>
    </dict>
    <key>Text Key Bindings</key>
    <dict>
        <key>Key Bindings</key>
        <dict>
            <key>^~ </key>
            <string>insertTabIgnoringFieldEditor:</string>
        </dict>
        <key>Version</key>
        <integer>3</integer>
    </dict>
</dict>
</plist>
like image 37
Thomas Avatar answered Oct 13 '22 00:10

Thomas