Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between "editor.insertSpaces" and "editor.tabSize" in settings?

How are they interpreted differently? I can only see what "editor.tabSize" does, which is the number of spaces that a tab occupies.

Thank you.

like image 371
suheti Avatar asked Sep 22 '15 15:09

suheti


2 Answers

From the configuration file:

{
  // Controls the rendering size of tabs in characters. 
  // If set to auto, the value will be guessed based on the opened file.
  "editor.tabSize": 4,

  // Controls if the editor will insert spaces for tabs. 
  // If set to auto, the value will be guessed based on the opened file.
  "editor.insertSpaces": true
}

As you can see editor.tabSize sets the size of space occupied when you enter tab. While editor.insertSpaces configures the stored key code in file.

If editor.insertSpaces equals false then Visual Studio Code will insert one #09 character for each tab. When you change editor.tabSize your existing code will change indentation in all lines a #09 character is stored.

If editor.insertSpaces equals true then Visual Studio Code will insert space characters for each tab instead of #09 characters. The amount of inserted spaces is configured in editor.tabSize. When you change editor.tabSize your existing code will not change indentation since there is no #09 character being stored in the file. Only new tab strokes will be affected by the new value of editor.tabSize.

If you and other team members use only tab for indentation then it is no problem to set editor.insertSpaces to false. If you and other team members use space or tab for indentation then you should set editor.insertSpaces to true. Otherwise your files can look awkward when somebody opens a file with a different value of editor.insertSpaces.

like image 105
Wosi Avatar answered Sep 22 '22 14:09

Wosi


editor.insertSpaces: Controls if the editor will insert spaces for tabs. Accepted values: "auto", true, false. If set to "auto", the value will be guessed when a file is opened.

editor.tabSize: Controls the rendering size of tabs in characters. Accepted values: "auto", 2, 4, 6, etc. If set to "auto", the value will be guessed when a file is opened.

like image 44
Benjamin Pasero Avatar answered Sep 24 '22 14:09

Benjamin Pasero