Move to beginning of text in Xcode

前端 未结 9 2050
说谎
说谎 2020-12-23 16:18

I know I can bind keys to \"Move to beginning of line\", but this ignores the indentation.

What I\'m looking for is to move to the beginning of text on a line, so th

相关标签:
9条回答
  • 2020-12-23 16:55

    Tested on XCode 10:

    Step1: Open the file located in the next path by a text editor

     /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist
    

    Add the next elements to the end of the file:

    <key>Sublime Commands</key>
    <dict>
        <key>Cut Current Line</key>
        <string>selectLine:, cut:</string>
        <key>Copy Current Line</key>
        <string>selectLine:, copy:</string>
        <key>Duplicate Current Line</key>
        <string>selectLine:, copy:, moveToBeginningOfLine:, paste:, moveToEndOfLine:</string>
        <key>Delete Current Line</key>
        <string>selectLine:, deleteToEndOfLine:, moveToEndOfLine:</string>
        <key>Move To First Char In Line</key>
        <string>moveToBeginningOfLine:, moveSubWordForward:, moveSubWordBackward:</string>
    </dict>
    

    The previous last key 'Move To First Char In Line' will do your request, but I mentioned also other keys.

    Now save the file.

    Step2: Close XCode and reopen it.

    Step3: Navigate to keybinding in xcode preferences then assign your shortcut.

    XCode -> Preferences -> Key Bindings Then search for 'Move To First Char In Line' and assign your shortcut.

    0 讨论(0)
  • 2020-12-23 16:56

    Use option + to jump across entire words.

    (That means, hold the option while pressing the left arrow key)

    0 讨论(0)
  • 2020-12-23 16:57

    In this Xcode extension, Linex, the feature Line Beginning can move to the first non-whitespace character in a line, and also toggle between that and the real beginning.

    Works for Xcode 9, perhaps Xcode 8.

    0 讨论(0)
  • 2020-12-23 17:05

    Actually, there is a faster and simpler way to achieve this as Mac OS supports some Emacs (or Unix) keybindings quite well.

    You can use Ctrl-a to jump to the beginning of a line. Which means, hold 'Ctrl' key and press 'a' on keyboard.

    For your more information, it is also handy to use
    Ctrl-e: jump to the end of a line
    Ctrl-n: move to next line
    Ctrl-p: move to previous line

    What's more, these fast keys can be used in terminal and text fields such as this StackOverflow answer editor on Mac OS, too.

    Hope that helps.

    0 讨论(0)
  • 2020-12-23 17:12

    I'm using Xcode 7.2 and was able to make my own macro to automate those 3 commands you mentioned above (cmd <-, opt ->, opt <-). You can edit the IDETextKeyBindingSet.plist file which defines all the key-bindings to add your own.

    Mine was located at /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist

    Add the following to create your own macro

    <key>Custom Keys</key>
    <dict>
        <key>Move to non-whitespace beginning of line</key>
        <string>moveToBeginningOfLine:, moveSubWordForward:, moveSubWordBackward:</string>
    </dict>
    

    Relaunch xcode and in your Preferences > Key Bindings tab, search for your custom macro and set it to cmd <-. Now it will run those 3 commands and effectively moves your cursor to the beginning of the text in the line.

    0 讨论(0)
  • 2020-12-23 17:17

    I don't have an exact solution, just one slight improvement for Xcode 4. You could set up a keyboard mapping for "Move Expression Left" (Xcode prefs > Key Bindings), which is a little more than Opt ←:

    s = [NSString string] |
    

    if | is the cursor position, pressing a "Move Expression Left" keystroke will bring it to the beginning of the expression on the left of it, so in that case before "[NSString". Opt ← will only move before "string".

    (Side note: I do see an action command called "Move to Left end of line" and another one called "Move to beginning of line." To my experience, these do exactly the same behavior in Xcode 4.0.2: this looks to me like a bug, unless I'm missing something.)

    0 讨论(0)
提交回复
热议问题