Sublime Text 2 move cursor out of parenthesis, quotes, or brackets

后端 未结 12 767
囚心锁ツ
囚心锁ツ 2020-12-22 20:10

I need a fast way to make the cursor jump outside the auto wrap qoutes or other syntax elements. I don\'t want to have to reach down to my arrow keys each time, and definit

12条回答
  •  萌比男神i
    2020-12-22 20:58

    I just have this feature partially implemented with the help of a plugin named run_multiple_commands.py (see below)

    (only tested on ST3, but the plugin is earlier than the first version of ST3 and should work on ST2 too).

    Shortcut configuration is as below:

    {
        "keys": ["shift+space"],
        "command": "run_multiple_commands",
        "args": {
            "commands": [
                {"command": "move", "args": {"by": "characters", "forward": true} }
            ]
        },
        "context":
        [
            { "key": "preceding_text", "operator": "regex_contains", "operand": "[)\\]}'\"]$", "match_all": true},
            { "key": "auto_complete_visible", "operator": "equal", "operand": false }
        ]
    },
    
    {
        "keys": ["shift+space"],
        "command": "run_multiple_commands",
        "args": {
            "commands": [
                {"command": "move", "args": {"by": "characters", "forward": true} },
            ]
        },
        "context":
        [
            { "key": "following_text", "operator": "regex_contains", "operand": "^[)\\]}'\"]", "match_all": true },
            { "key": "auto_complete_visible", "operator": "equal", "operand": false }
        ]
    },
    
    {
        "keys": ["shift+space"],
        "command": "run_multiple_commands",
        "args": {
            "commands": [
                {"command": "move_to", "args": {"to": "brackets"} },
            ]
        },
        "context":
        [
            { "key": "following_text", "operator": "regex_contains", "operand": "^[(\\[{]", "match_all": true },
            { "key": "auto_complete_visible", "operator": "equal", "operand": false }
        ]
    },
    
    {
        "keys": ["shift+space"],
        "command": "run_multiple_commands",
        "args": {
            "commands": [
                {"command": "move_to", "args": {"to": "brackets"} },
                {"command": "move", "args": {"by": "characters", "forward": true} },
            ]
        },
        "context":
        [
            { "key": "following_text", "operator": "not_regex_contains", "operand": "^[)\\]}'\"]", "match_all": true },
            { "key": "preceding_text", "operator": "not_regex_contains", "operand": "[)\\]}'\"]$", "match_all": true},
            { "key": "following_text", "operator": "not_regex_contains", "operand": "^[(\\[{]", "match_all": true },
            { "key": "auto_complete_visible", "operator": "equal", "operand": false }
        ]
    },
    

    One shortcut (shift+space) for four conditions:

    1. cursor is just after quotes or closing parentheses/bracket:

      move one character forward

    2. cursor is just before quotes or closing parentheses/bracket:

      move one character forward

    3. cursor is just before opening parentheses/bracket:

      move to closing parentheses/bracket

    4. !1 && !2 && !3:

      move to closing parentheses/bracket

      and move one more character forward

    To use this configuration in your ST, you should first add a file named run_multiple_commands.py to your .../Package/User/ directory, and the content of which is the second code piece of This Article

    This solution is just fine for everyday use but is not perfect because:

    1. the cursor is unable to jump out of quotes (just step over it when the cursor is directly followed by one).
    2. the cursor is unable to jump out of the nearest parenthesis, quotes, or brackets when the code block is commented.

提交回复
热议问题