0

My question is related to this question about turning off parenthesis matching in Sublime Text 2.

Sublime Text 2/3 has the setting "auto_match_enabled", which automatically pairs delimiters ([ ],{ }," ", etc.). Most of the time this is a great feature. When writing certain documents, however, it gets in the way.

For instance, in LaTeX the double quotes are used (almost?) exclusively to add in umlauts. So, e.g., n\"aive gets compiled as näive. In this situation the automatic insertion of the matching double quote is not helpful -- it adds a keystroke to delete it. Given this, I would like to turn off auto matching only for double quotes and only in files with a .tex extension. Unfortunately, the global setting seems like an all-or-nothing deal -- there is no obvious (to me) way to restrict its scope.

How do I turn off auto matching for a single type of delimiter in a given context? More specifically, how do I turn off auto matching for double quotes in files with a .tex extension?

1

Similar to Jonno's answer above, you can modify the keymap settings for a given package in the same way:

Create a Default.sublime-keymap file in the LaTeX directory (create folders if needed):

Windows:
%APPDATA%\Sublime Text 3\Packages\LaTeX\Default.sublime-keymap

macOS:
~/Library/Application Support/Sublime Text 3/Packages/LaTeX/Default.sublime-keymap

Linux:
~/.config/sublime-text-3/Packages/LaTeX/Default.sublime-keymap

You can then copy & paste the default keymap (Preferences -> Key Bindings - Default) settings for double quotes into this new file. Then I modified the actions of those key bindings to no longer insert quoted pairs. This is the result of my changes:

[
    // changed snippet arg contents from `"\"$0\""` to `"\""` to prevent inserting paired quotes
    { "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\""}, "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 - punctuation.definition.string.end", "match_all": true }
        ]
    },
    // changed the command and args from `move` to the same command/args as above to prevent skipping auto-inserted quotes
    { "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\""}, "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 },
            { "key": "selector", "operator": "not_equal", "operand": "punctuation.definition.string.begin", "match_all": true },
            { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double - punctuation.definition.string.end", "match_all": true },
        ]
    }
]

Notes:

  • I did not change the backspace operator (seen in the default keymap) when surrounded by quotes. I'm not exactly sure how to fix or if the behavior is incorrect or not
  • Your default keybindings may be different than mine, feel free to make the same changes I described in comments above
  • I imagine you can remove the entire context section and it work, but I did not try that out myself.
  • I’ve just been living with this issue, thanks for bringing this question back from the dead, oh wise necromancer. – Dennis Nov 1 '17 at 3:13
3

I'm afraid I don't have a solution for only double quotes, but if you want to disable just for LaTeX you can create the following file:

(This is for Sublime Text 3 - I believe it's similar for Sublime Text 2 though)

%APPDATA%\Sublime Text 3\Packages\LaTeX\LaTeX.sublime-settings

You may need to create the folder structure, and you can add any LaTeX specific settings here, in your case:

{
    "auto_match_enabled": false,
}

As I said and as I think you know, this will apply to all matching, I don't have an answer for only double quotes I'm afraid, but hopefully this will help with the LaTeX specific side.

  • Thanks for the partial answer! Unfortunately, I fear that the other half is going to be where things get tricky. I'll tinker a bit, but hopefully some Sublime wiz comes through with a neat trick. – Dennis Jan 15 '16 at 6:18
  • @Dennis Fingers crossed :) – Jonno Jan 15 '16 at 6:18
  • this worked for me. It was doing this for me using SCSS – Ronnie May 9 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.