Sublime Forum

How to change space indentation width

#1

I know this is common, but hear me out.

context: i’ve started working on a project that uses spaces instead of tabs

  • being sublime, this is not really a concern because i can still press TAB and a space indentation will come out
    Also, i’m working in a vue file

The problem is with the width of one indent level.

I tried setting from sublime tab width to 4 (from 2) and try to reindent the whole file to be correctly indented, because for some reason sublime does not reindent the file after width change

Anyway. I reindent the template block - ok. I reindent the style block - ok

I get to the script block. Not ok.
For some reason when i am inside the script block, if i put a TAB, the eslint says: Expected indentation of 2 spaces but found 4. If I manually press space twice instead of TAB, it works ok because there are 2 spaces.

Can you please help me?

0 Likes

#2

Do you want to make a file can be both 2-space indented and 4-space indented depending on the scope of the current cursor position?

AFAIK, the tab-width setting is syntax-specific and only applies to the whole file. But yeah, it’s possible that people can write a plugin to change it dynamically depends on the current scope.


If you want to convert a 4-space indented file into a 2-space indented one, I typically convert the file from space-indented to tab-indented -> change tab-width to 2 -> convert the indentation back to space.

0 Likes

#3

no no, i think you misunderstood me

I want to have the same indentation in the file. The current behaviour is wrong, as far as eslint tells me. The current behaviour sets 4 spaces instead of 2 in the section - reported by eslint.

These guys use space indentation instead of tabs, so I need to comply. But i also do not want my code to be so condensed so i wanted a space indentation width to be bigger.

Does tab size = 4 mean that a indentation level is composed of 4 spaces or that visually it has the size of 4 spaces but in reality is only one space?

0 Likes

#4

How this is interpreted depends on whether or not you’re using physical tab characters or not; if you’re indenting using physical tabs, then tab_size of 4 sets how wide Sublime thinks that should be visually, but behind the scenes it’s really just a single character.

On the flip side, when you have translate_tabs_to_spaces turned on (which is what Indent using spaces does), then tab_size specifies how many spaces a tab should be converted into when you try to insert one, and physical tab characters can’t appear in the file.

In short, when you’re indenting with spaces, what you see is what the file actually is; no matter who opens the file or what looks at it, it’s seeing it exactly the way that you’re seeing it. When you’re using physical tab characters, then the file looks different to different people depending on what they consider the one true tab size setting to be.

This is only possible if you want to go to the work of converting all of the space indentation to tabs when you start working on a file, and converting all of the tab indentation back to spaces when you’re done with it.

Essentially, make sure that the status bar says Spaces: 2, then click on it and choose Convert indentation to tabs, followed by clicking on it again and changing it to Tab width: 4; now the file is tab indented instead of space indented, so it will appear wider. When you’re done, reverse the steps to set the tab width back to 2 followed by Convert indentation to spaces.

0 Likes

#5

this is what i was afraid of :expressionless:

i just wanted that those default 2 spaces indentation to visually appear like 4 spaces

thank you for your support

0 Likes