Sublime Forum

Keybind for Convert to tabs to spaces and vice-versa

#1

Hi,

I did some research in the documentation and i did not found a way to map a keybind for convert tabs to space. Is there a way ? I looked at the commands reference, but i did not saw any command that does this.

Thanks for the help !

1 Like

#2

View > Indentation contains two similar commands:

Convert Indentation to Spaces
Convert Indentation to Tabs

If you then search Packages/Default/Main.sublime-menu, you will find the actual command names:

expand_tabs
unexpand_tabs

They might do what you want.

1 Like

#3

Thanks a lot, @guilhermoo !

It is exaclty what i was searching for.

Thanks again =)

0 Likes

#4

Also, if you run the command sublime.log_commands(True) e.g. from the console, then you can see all commands executed in the console. Clicking “Convert Indentation to Spaces” from either the menu or from ctrl+shift+p will then print this in the console:command: expand_tabs {"set_translate_tabs": true} Bingo!

1 Like

#5

I added this to my shortcuts Default (Linux).sublime-keymap file, it works! Thanks for the tips.

	{ "keys": "ctrl+shift+alt+~"], "command": "unexpand_tabs", "args" : {"set_translate_tabs" : true} } 
1 Like

#6

For convert tabs to spaces,
Shouldn’t this be "expand_tabs" with "set_translate_tabs"
(instead of "unexpand_tabs")?

And for the opposite, convert spaces to tabs, would it be:
"unexpand_tabs" with "set_translate_tabs": false ?

0 Likes

#7

Below are the menu items configurations, it looks like set_translate_tabs is always true & expand_tabs converts to spaces & unexpand_tabs converts to tabs:

{
    "command": "expand_tabs",
    "caption": "Convert Indentation to Spaces",
    "args": {"set_translate_tabs": true}
},
{
    "command": "unexpand_tabs",
    "caption": "Convert Indentation to Tabs",
    "args": {"set_translate_tabs": true}
}
1 Like

#8

Thanks, you are a savior!

0 Likes