Home Download Buy Blog Forum Support

How do I add additional "brackets" to auto close?

How do I add additional "brackets" to auto close?

Postby jlippiner on Sun Nov 20, 2011 12:30 pm

I noticed that Sublime is not auto closing the pipe "|" symbol in Ruby (or HAML) for me. In Ruby it's pretty common to use |x| in a block, a lot more than using just a |, and I would like | to auto close to |cursor| without a tab just like quotes or {} does. Any thoughts?
jlippiner
 
Posts: 4
Joined: Sun Nov 20, 2011 12:28 pm

Re: How do I add additional "brackets" to auto close?

Postby iamntz on Sun Nov 20, 2011 1:06 pm

Edit your keymap file and add this:
Code: Select all
  { "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": "preceding_text", "operator": "not_regex_contains", "operand": "[\"a-zA-Z0-9_]$", "match_all": true },
      { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double", "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 }
    ]
  },
  { "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 }
    ]
  },
  { "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "Packages/Default/Delete Left Right.sublime-macro"}, "context":
    [
      { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
      { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
      { "key": "preceding_text", "operator": "regex_contains", "operand": "\\|$", "match_all": true },
      { "key": "following_text", "operator": "regex_contains", "operand": "^\\|", "match_all": true }
    ]
  }


That should be enough.
iamntz
 
Posts: 920
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 12 guests