Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid auto indent when saving in Visual Studio Code

I want to avoid auto indent behaviour when I save a (javascript) file in Visual Studio Code without turning off complety auto indentation.

I have this code (and I would like to keep this indentation if possible):

const $tab_a = $('tab_a')
const $tab_b = $('tab_b')

;[$tab_a, $tab_b].forEach($e => $e.onclick = () => {
  if ($e.className) return
  $tab_a.classList.toggle('active')
  $tab_b.classList.toggle('active')
})

However, every time I save with Visual Studio Code it changes indentation like this:

const $tab_a = $('tab_a')
const $tab_b = $('tab_b')

  ;[$tab_a, $tab_b].forEach($e => $e.onclick = () => {
    if ($e.className) return
    $tab_a.classList.toggle('active')
    $tab_b.classList.toggle('active')
  })

I tried different settings in Visual Studio Code:

  1. Editor: Auto Indent (default: full) -> none
  2. Editor: Wrapping Indent (default: same) -> none
  3. All combinations and restarting VSCode

Unfortunatly any of them worked for me.

Any help will be really appreciate it.

Note: I'm not using extensions.

like image 660
Chumpocomon Avatar asked May 14 '26 13:05

Chumpocomon


2 Answers

To turn off formatting on save:

  1. Go to File | Preferences > Settings
  2. Type "save" in the search box
  3. In the list, choose Text Editor | Formatting
  4. Untick the box for Editor: Format On Save

That sets the "editor.formatOnSave" setting to false in settings.json.

When I did that, your example was left alone when I saved the file. (Whereas with the setting on, it gets reformatted as you describe in the question when I save it.)

like image 162
T.J. Crowder Avatar answered May 16 '26 03:05

T.J. Crowder


check setting.json (ctrl+shift+p then choose 'Preferences: Open Settings (Json)' ) for:

"editor.formatOnSave": true/flase

it should be set by default to false but maybe some extension toggled to true so just change it back to false.

Hope that helps

like image 32
itay_alon Avatar answered May 16 '26 03:05

itay_alon