Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Sublime Text 3, when writing CSS files, if I type a colon, a semicolon will automatically be inserted after the caret. This is no doubt useful to many, but I'm among the users who are inconvenienced by this.

How can I disable this auto-insertion of semicolons?

I would like to do this without globally disabling auto-insertion. I am very happy with it inserting a closing brace after I type an opening one - it is specfically the colon/semi-colon auto-insertion that inconveniences me.

I recall finding a way to disable it when I was using ST2 a few months ago, but I'm not sure how to do it in ST3.

share|improve this question

1 Answer 1

The CSS package included with ST (2 and 3) includes a keybinding snippet to auto-insert a semi-colon after a colon. In ST2 you could easily edit the keybinding to remove this feature, as all packages were in the same directory and you could access each file through the filesystem. However, the decision was made in ST3 to compress packages into .sublime-package zip files, and while there are a few roundabout ways of editing the contents, in this case it's easiest to just override the keybinding in your own settings.

Go to the Preferences menu and click on Key Bindings - User. If this file is empty, paste the following into it:

[
    // override CSS auto-insertion of semi-colon
    { "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": "selector", "operator": "equal", "operand": "source.css - meta.selector.css", "match_all": true },
            { "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\}|$)", "match_all": true }
        ]
    }

]

If you already have custom keybindings, just omit the outer square brackets [ ], place a comma , after the last keybinding, and paste the rest at the end before the final closing square bracket ].

If you're interested, the original keybinding contained "args": {"contents": ":$0;"} - I just removed the ; from after the $0 (which means "put the cursor here").

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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