Search code examples
sublimetext2key-bindingssettings

Keybind setting to skip past auto-pair end characters in Sublime Text 2


I want to be able to have the cursor move past the autopair ending character so I can continue typing my code.

I'm a noob to Sublime Text. I was looking through here at SO and found this post which uses this type of code (snippet):

//Tab skips to end of autopaired characters
{ "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true},

And I then added to my Default(Windows)sublime-keymap -- User file like this:

//Tab skips to end of autopaired characters
    { "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true},
      "context":[

       ]
    }

When I press the 'tab' key to make the cursor move past the closing autopair, the cursor moves to a tab stop (adding 4 spaces by default), it doesn't move "forward" like pressing an arrow key would do.

How can get the cursor just move forward using the tab key or some other key? What am I missing/doing wrong here? I don't want to have to use the arrow keys as doing so is not a natural keystroke from the home keys (esp. depending upon the user keyboard). Thanks!


Solution

  • The question you linked actually had it right—you just removed the context key array, which effectively told Sublime Text that you never wanted Tab to move the cursor forward by one character. Use the asker's complete key binding:

    { "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
        [ 
            { "key": "selection_empty", "operator": "equal", "operand": true },
            { "key": "preceding_text", "operator": "not_regex_match", "operand": "[[:space:]]*", "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^[\"'\\)\\}\\]\\_]", "match_all": true },
            { "key": "auto_complete_visible", "operator": "equal", "operand": false },
            { "key": "has_next_field", "operator": "equal", "operand": false } 
        ] 
    },
    

    You can read more about key bindings and contexts at the Unofficial Docs Key Bindings page.