Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indentation in VS Code

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.

like image 678
Gonçalo Marrafa Avatar asked Jul 09 '17 10:07

Gonçalo Marrafa


People also ask

How do you indent a code?

Should You Use Tab or Space to Indent? Technically, it is fine to either indent using the tab key or with the space bar. Indenting once with the tab key means just pressing the tab key once. Indenting once with the space bar means pressing the space bar 4 times.


2 Answers

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.

like image 182
nick Avatar answered Oct 08 '22 04:10

nick


Look at that to avoid content duplication
- https://stackoverflow.com/a/46856413/7668448
- https://stackoverflow.com/a/46855721/7668448

Also think about setting

  • "editor.formatOnPaste"
  • "editor.formatOnType"
  • "editor.formatOnSave"

to true, they default to false.

That of course by going to user settings (file>preference>settings or through pallet Ctrl+shift+P and write setting you will find within the choices).

Also it's a good thing to do the following: in default settings, in search settings bar, you write "format", then scroll and go through all the parameters related to formatting, it's a long list, but there is a lot of cool things.

like image 41
Mohamed Allal Avatar answered Oct 08 '22 04:10

Mohamed Allal