Sublime Forum

Parenthesis/brackets auto-closing doesn't work under some conditions

#1

when there’s a character like , or : right after the cursor, and i type a opening parenthesis, bracket or curly braces, it doesn’t get auto-closed.

for example, let’s say i have the cursor at |.
some(func|, arg2)
if i type (, it becomes:
some(func(|, arg2)
and ‘)’ is not automatically inserted.

how can i make it so it gets auto-closed no matter what character is after the cursor?
i did some google search but couldn’t find any solutions.

by the way english is not my first language.

0 Likes

#2

Add this to your key bindings file: (Preferences > Key Bindings)

{ "keys": ["("], "command": "insert_snippet", "args": {"contents": "(${0:$SELECTION})"}},
{ "keys": ["["], "command": "insert_snippet", "args": {"contents": "[${0:$SELECTION}]"}},
{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{${0:$SELECTION}}"}},

This should do the trick!

In case anyone is interested, I found this by searching for "keys": ["("] in the default key bindings file and then editing the command until I got something that did what you wanted.

1 Like

#3

it works! thanks for your quick answer!

1 Like

#4

It uses snippets, if you want to learn more: http://docs.sublimetext.info/en/latest/extensibility/snippets.html

(they save me a lot of time)

0 Likes

#5

thanks for the information! i’ll take a look at it.

1 Like