Indentation in VS Code

Gonçalo Marrafa picture Gonçalo Marrafa · Jul 9, 2017 · Viewed 72.5k times · Source

I'm a long time Emacs user. I've been trying out VS Code and i like it so far.

One thing i love about Emacs is that it always indents the code correctly when i press tab. I've looked but i can't seem to get that behavior in VS Code. I've tried looking in the settings and searching for an extension but have had no luck.

Can anyone help me on this please? Is there an extension i can/have to install to get it to do what i want?

I code mostly in PHP, HTML, CSS and Javascript.

Thanks in advance.

Answer

nick picture nick · Jul 10, 2017

A couple things:

To format (make "pretty") all the code in a given file you can use Shift + Alt + F on Windows. See this answer for more information.

To adjust the user settings for tab size or to insert tabs as spaces, etc. you can edit settings.json (Ctrl + Shift + P then type "user settings"). You can then manually add/edit:

// number of spaces for a tab
"editor.tabSize": 2,

// insert spaces when pressing tab
"editor.insertSpaces": true

I believe both of these settings are overriden by "editor.detectIndentation" so you may have to look at that too.