Black
Black

Reputation: 20232

Visual Studio Code - Convert tabs to spaces for all files in folder

I know I can manually replace tabs to spaces like this:

  1. F1,
  2. indentationToSpaces
  3. Enter.

Is there a way to do this for all files in a folder (+ files in subfolders)?

Upvotes: 2

Views: 1459

Answers (1)

Daniil Loban
Daniil Loban

Reputation: 4381

Ok. I think, you are looking for an extension. But my answer is a litle trick - using the global replacer with regex:

We change step by step to save the amount of indentation and replace tabs only in the start of line.

enter image description here

The below snippet shows replace step by step,s presents one space and _ precents one tab:

test = '_____Text__'
for(let i=0; i < 7; i++){
  test = test.replace(/^([ ]*)(_)/, "$1 ")
  console.log( 'step', i, test.replace(/[ ]/g, 's'))
}

You may use two spaces instead one.

But this solution has 1 issue - after replace you must update regexp (for example: add and remove space) for activate this button again

enter image description here

So at the end steps look like:

  1. fill: regexp, replace, files to include
  2. click replace
  3. update regexp or click twice on one of this buttons: enter image description here
  4. repeat from step 2 some times

Upvotes: 1

Related Questions