Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there some configuration or plugin I can use which would add spaces to the inside of parentheses when they're matched. Here's an example of what I'm trying to explain.

if (^) // ^ represents cursor position
if ( ^ ) // Where I want the cursor to be positioned.
share|improve this question
up vote 4 down vote accepted

You can edit the auto-pair functionality. I copied the following from "Key Bindings - Default" into "Key Bindings - User". Add spaces in the contents values. You can do something similar for square and curly brackets. The first setting sets it for normal use. The second sets it for when you have text highlighted.

// Auto-pair brackets
{ "keys": ["("], "command": "insert_snippet", "args": {"contents": "( $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 }
  ]
},
{ "keys": ["("], "command": "insert_snippet", "args": {"contents": "( ${0:$SELECTION} )"}, "context":
  [
    { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
    { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
  ]
},

Edit To make the key binding syntax specific, add a line at the bottom of the context values. You will have to find the syntax's scopeName. For example html is text.html and sass is source.sass.

{ "keys": ["("], "command": "insert_snippet", "args": {"contents": "( $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 },
    { "key": "selector", "operator": "equal", "operand": "source.sass" }
  ]
},
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .