2

In sublime, if you type, alert("{<cursor> it will autocomplete the closing brackets and quotes to: alert("{<cursor>}").

In visual studio, if you hit tab, it will place the cursor at the end of the autocompleted characters.

How can I replicate this exact behaviour in sublime? I don't see much point in autocompletion if you have to type those characters anyway or use arrow keys.

user2787904
  • 517
  • 2
  • 7
  • 18

2 Answers2

4

Building on @AGS's answer and your comment, there are two possible options. The first (if you're not using OS X) is to just hit End, which will move the cursor to the end of the line (eol).

The second option is to slightly modify @AGS's keymap to the following:

{ 
    "keys": ["shift+enter"], "command": "move_to", "args": {"to": "eol", "extend": false}, "context":
    [
        { "key": "following_text", "operator": "regex_contains", "operand": "^[)\"\\]\\}\\$]", "match_all": true },
        { "key": "auto_complete_visible", "operator": "equal", "operand": false }
    ]   
}

The binds the eol functionality to ShiftEnter, and includes the regex support, which can be removed if you want.

I hope this helps!

Community
  • 1
  • 1
MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • This isn't a perfect solution if you already have other text on the line after the `alert("{}")`, if you need to modify it for that use case just let me know. – MattDMo Nov 13 '13 at 15:02
  • That would be nice but this will do just fine in 99% of cases so marking it as answered. – user2787904 Nov 13 '13 at 15:07
3

Edit your .sublime-keymap file and add

// Skip past round and square autocomplete brackets
    { 
        "keys": ["shift+enter"], "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 }
        ]   
    },

In this case, shift + enter will function like tab in visual studio.

The solution is originally not mine - I found it either here or on the ST2 forum.

AGS
  • 14,288
  • 5
  • 52
  • 67