Sublime Forum

auto_match_enabled without ignoring quotes before end quote?

#1

I like the automatic pairing of quotes, brackets, parentheses, etc. via auto_match_enabled = true in the settings.

However I often find myself being thrown off when I have my cursor to the immediate left of the closing quote, and attempt to type another quote. Instead of adding a new quote character, Sublime text sees that there is a closing quote, and just shifts the cursor to the right of the quote.

I find this second mechanic incredibly unintuitive, and it gives me problems especially when I’m working with lots of nested quotes/brackets, or when I want to set up nested parentheses. It can even feel like I’m fighting the program. I realize that with the correct workflow this shouldn’t happen, but I guess it’s just not how I work.

I was wondering, is there a way to disable this? I like that it auto completes the quote in the first place, but I don’t like when it prevents me from starting a new quote to the immediate left of a closing quote character.

0 Likes

Unexpected consequences of "auto_match_enabled": false,
#2

You can override any binding from Default ({your os}).sublime-keymap in your User folder. The relevant section is at lines 278 or so and ff.

I’m not 100% sure I’ve understood what you want to happen. Here’s what I think you want:

(|) -> ((|))

With the | standing in for the cursor.

If so, here’s what you would use:

    { "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": "^\\)", "match_all": true }
        ]
    },

I’m using the parenthesis as an example because it makes it reasonably clear what’s going on. You would need to replicate & modify this snippet for the ", ``, { and '.

If there’s a simpler way to override the bindings, I don’t know it :smile:

Hope this helps,
Alex

0 Likes