Skip to content

Instantly share code, notes, and snippets.

@koulmomo
Created January 13, 2014 08:41
Show Gist options
  • Save koulmomo/8396647 to your computer and use it in GitHub Desktop.
Save koulmomo/8396647 to your computer and use it in GitHub Desktop.
Perfect Sublime Text 2 Key Bindings. Tab to skip out of brackets, braces, parentheses, and quotes/quotations but still be able to indent
[
// Move out of common paired characters () and [] with `Tab`
{
"keys": ["tab"],
"command": "move",
"args": {"by": "characters", "forward": true},
"context": [
// Check if next char matches (followed by anything)
{ "key": "following_text", "operator": "regex_match", "operand": "(:?`|\\)|\\]|\\}).*", "match_all": true },
// ...and that there is a paid character before it on the same
// line. This lets you `tab` to Indent at lines with single ]s
// still, like in a JSOn file
{ "key": "preceding_text", "operator": "regex_contains", "operand": "(:?`|\\(|\\[|\\{)", "match_all": true }
]
},
// Move out of single and double quotes with `Tab`
{
"keys": ["tab"],
"command": "move",
"args": {"by": "characters", "forward": true},
"context": [
{ "key": "following_text", "operator": "regex_match", "operand": "(?:\"|').*", "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "(?:\"|')", "match_all": true }
]
}
]
@Voldiemert
Copy link

Thank you!!!! I'm using this on Linux and it's working like a charm.Does this work on all platforms?

@fiuky
Copy link

fiuky commented Dec 10, 2014

Thank you! This was very helpful.

@ManasN
Copy link

ManasN commented Jan 26, 2015

This kept me from leaving sublime :)

@mattkj
Copy link

mattkj commented Feb 5, 2015

Awesome, thanks!

Copy link

ghost commented Apr 25, 2015

works great for Sublime 3 too!

@GRAgmLauncher
Copy link

This is great, but breaks tabbing through tab points in snippets (e.g. a tab point for method arguments, followed by another tab point to the method body. Would be awesome if somehow it could look to see if there was a snippet tab point to jump to rather than just moving outside of the current delimiters.

@sheng-sz
Copy link

Agree with GRAgmLauncher. Is it possible to not avoid breaking snippets?

@ccnixon
Copy link

ccnixon commented Aug 3, 2016

Try adding: {"key": "auto_complete_visible", "operand": false}, as an element of the context array.

@sierra-kilo
Copy link

Im copy pasting this into my keybindings for user, but keep getting an error.

Error trying to parse file: Unexpected trailing characters in ~/Library/Application Support/Sublime Text 2/Packages/Default/Default (OSX).sublime-keymap:40:2

I tried removing some brackets then I get a comma error, I put commas, comes back to this error, any help would be appreciated. thanks

@idr4n
Copy link

idr4n commented Jun 12, 2017

I found another way which lies within sublime keybindings itself. Basically, I just modify the keybindings for auto closing parens, that is, I replace "contents": "($0)" with "contents": "($1)$0". Then just hit Tab to get out of the parenthesis. So I add in my keybindings the following:

{ "keys": ["("], "command": "insert_snippet", "args": {"contents": "($1)$0"}, "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": "^(?:\t| |\\)|]|;|\\}|$)", "match_all": true }
    ]
  },

And similar for square brackets, curly brackets, and single and double quotes.

@srxrt
Copy link

srxrt commented Jul 2, 2020

can you make one for Brackets as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment