Sublime Forum

[Solved] How to config keyboard shortcuts to increase/decrease tab size (not directly set it to some value)?

#1

Hi you guys,

I used to have this in my keymap to increase/decrease tab size on the fly, and it works fine as expected:

...
    { "keys": ["ctrl+alt+["], "command": "change_tab_size", "args":{"increase":false}},
    { "keys": ["ctrl+alt+]"], "command": "change_tab_size", "args":{"increase":true}},
...

I don’t remember where I come to this command though (I just did a google search and find nothing using the keywords "change_tab_size" sublime text, weird).

Anyway, recently this dose not work anymore. I checked and didn’t find any key conflicts or such things (no errors in console either), so I’m posting here to ask, is this command been dropped or how I’m supposed to get this to work again?

ST3, build 3126 @ Windows 7 64bit

Thanks!

0 Likes

#2

I ended up writing a small command myself:

class ChangeTabSizeCommand(sublime_plugin.TextCommand):
    def run(self, edit, increase = True, step = 1):
        max_tab_size = 200
        min_tab_size = 2
        settings = self.view.settings()
        current_tab_size = settings.get("tab_size")
        if increase :
            if current_tab_size >= max_tab_size :
                return
            else :
                settings.set("tab_size", current_tab_size + step)
        else :
            if current_tab_size <= min_tab_size :
                return
            else :
                settings.set("tab_size", current_tab_size - step)

and in your keymap file:

   { "keys": ["ctrl+alt+["], "command": "change_tab_size", "args":{"increase":false}},
   { "keys": ["ctrl+alt+]"], "command": "change_tab_size", "args":{"increase":true}},

should work, and even better you can change the step size:

   { "keys": ["ctrl+alt+["], "command": "change_tab_size", "args":{"increase":false, "step":2}},
   { "keys": ["ctrl+alt+]"], "command": "change_tab_size", "args":{"increase":true, "step": 2}},

hope this helps someone.

3 Likes