Home Download Buy Blog Forum Support

Using tab to escape auto-completed quotes

Using tab to escape auto-completed quotes

Postby Johannes on Fri Jul 19, 2013 4:05 pm

The automatic-quote/bracket completion in Sublime Text is very useful, but I've found myself often wanting to use tab to jump to the right of an auto-completed quote.

Tab is easily accessible, and the alternative (moving my right hand to hit the right arrow) just feels a little cumbersome and, at least for me personally, feels like it really slows me down. Sure it's only a few milliseconds, but it just feels cumbersome.


Would anyone know how to set up a custom keybinding that when tab is pressed moves the cursor one character to the right, if and only if there is a quote or bracket to the right of it?

Alternatively are there any ways people rely on (other than VIM - I'm not that hardcore yet) to move the cursor over the auto-completed brackets/quotes?
Johannes
 
Posts: 18
Joined: Sun Dec 11, 2011 1:44 am

Re: Using tab to escape auto-completed quotes

Postby adzenith on Fri Jul 19, 2013 4:51 pm

Check out the default key bindings, e.g.:
Code: Select all
   { "keys": ["]"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
      [
         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
         { "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true }
      ]
   },
adzenith
 
Posts: 1213
Joined: Mon Oct 19, 2009 9:12 pm

Re: Using tab to escape auto-completed quotes

Postby Johannes on Sun Jul 21, 2013 5:36 pm

adzenith wrote:Check out the default key bindings, e.g.:
Code: Select all
   { "keys": ["]"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
      [
         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
         { "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true }
      ]
   },



Cheers! That worked a charm.

For anyone else that might want it, here is the modified code
Code: Select all
{ "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
      [
         { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
         { "key": "auto_complete_visible", "operator": "not_equal", "operand": true },
         { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
         { "key": "following_text", "operator": "regex_contains", "operand": "^(\\]|\\)|\\}|>|\\\"|'|\\;)", "match_all": true }
      ]
   }

It makes it so pressing tab moves the cursor forward one step if it is before any of the following characters (not including commas):
Code: Select all
], ), }, >, ", ', ;


Edit: I've modified the code to allow for auto-completion. There are probably other cases where this breaks, but I'll try to fix them if I find any.
Johannes
 
Posts: 18
Joined: Sun Dec 11, 2011 1:44 am

Re: Using tab to escape auto-completed quotes

Postby iamntz on Mon Jul 22, 2013 2:18 pm

Small improvement: also add this condition:

Code: Select all
{ "key": "has_next_field", "operator": "not_equal", "operand": true }


This way, if you have snippets that uses any of those operands, will keep working.
iamntz
 
Posts: 898
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 13 guests