Search code examples
xcodexcode4editor

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


Solution

  • 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>