Sublime Forum

Set default indentation

#1

Hi, I have a project where some files are indent with tab and some are indent with spaces.

My personal preference is to indent with spaces, but I cannot convert each file one by one since there are too many.

Is there an easy setting where the indentation would become spaces and ignore the original file indentatoin setting?

I have tried the below setting but they are not working.

"translate_tabs_to_spaces": true,
"detect_indentation": false,
0 Likes

#2

Turning those settings on will make Sublime try to use them for new files as well as for files that you open, but they don’t physically modify the content that is already in the file.

In particular, translate_tabs_to_spaces tells Sublime that when something tries to insert a physical tab character, it should convert it into the appropriate number of spaces.

So, the only way forward would be to actually physically convert the files. There is a built in command for this, which you can find in the menu under View > Indentation, though if you do it frequently that is a bit of a drag.

You could however bind it to a key:

{ 
  "keys": ["ctrl+shift+h"],
  "command": "expand_tabs" 
},

Alternately you could use a simple plugin to trigger the command whenever a file is loaded; though that might be a bit heavy handed, so the manual approach with the key binding may be more acceptable.

1 Like