Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I customize the tab-to-space conversion factor?

How do I customize the tab-to-space conversion factor when using Visual Studio Code?

For instance, right now in HTML it appears to produce two spaces per press of TAB, but in TypeScript it produces 4.

like image 765
J. Abrahamson Avatar asked Apr 30 '15 15:04

J. Abrahamson


People also ask

How do I change the tab spacing or code?

Type “Indentation” into the search field then head to the “Editor: Tab Size” section. Replace the default space number with your preferred one: Your setting will be applied and reflected immediately. If this doesn't happen (it's a little lag sometimes), just reload or restart your VS Code.

How do I change my tab to two spaces?

Go to the Language Menu/Tab Settings tab. Make sure [Default] is selected in the rightmost list. At The bottom right, click the blue underlined number beside the Tab size: Press 2, and press enter.

How do I change the default space in VS Code?

You can click on the Status Bar indentation display to bring up a dropdown with indentation commands allowing you to change the default settings for the open file or convert between tab stops and spaces.


1 Answers

By default, Visual Studio Code will try to guess your indentation options depending on the file you open.

You can turn off indentation guessing via "editor.detectIndentation": false.

You can customize this easily via these three settings for Windows in menu FilePreferencesUser Settings and for Mac in menu CodePreferencesSettings or ⌘,:

// The number of spaces a tab is equal to. This setting is overridden // based on the file contents when `editor.detectIndentation` is true. "editor.tabSize": 4,  // Insert spaces when pressing Tab. This setting is overriden // based on the file contents when `editor.detectIndentation` is true. "editor.insertSpaces": true,  // When opening a file, `editor.tabSize` and `editor.insertSpaces` // will be detected based on the file contents. Set to false to keep // the values you've explicitly set, above. "editor.detectIndentation": false 
like image 181
Alex Dima Avatar answered Sep 29 '22 06:09

Alex Dima