2

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)?

Black
  • 18,150
  • 39
  • 158
  • 271
  • 1
    Does this answer your question ? https://stackoverflow.com/a/11094620/13944524 – S.B Oct 18 '22 at 10:57
  • Kind of, Thx! is there also a way to do this via VSC? – Black Oct 18 '22 at 11:01
  • 1
    you can use extension [Command on All Files](https://marketplace.visualstudio.com/items?itemName=rioj7.commandOnAllFiles) – rioV8 Oct 18 '22 at 11:13
  • @rioV8 it is unclear how to use it. Their example is bad. – Black Oct 18 '22 at 12:15
  • with the key binding dialog you can find the VSC command that is mapped to a Command Palette command – rioV8 Oct 18 '22 at 12:32
  • 1400 installs does not mean that they understood it, the probably uninstalled it again like me. The extension does not work. I press F1 and write "commandOnAllFiles" but it says "no matching commands" – Black Oct 18 '22 at 12:37
  • in the Command Palette you need to search for `Apply 1 or more commands to all files in the Workspace`, but it does not work from the Command Palette because it needs a lot of arguments in the settings file. The number on the page is the number of people USING the extension – rioV8 Oct 18 '22 at 12:49
  • Ok how am I supposed to know that I need to write `Apply 1 or more commands to all files in the Workspace` in the command pallette? This is described nowhere. There are missing basic informations. And if it does not work from the command pallette, then how on earth does it work? – Black Oct 18 '22 at 12:51
  • Ok so I figured out I have to add a hotkey instead, but it does not execute my intendation to space command... a review also says that it does not work, he tried the same. – Black Oct 18 '22 at 12:59
  • see also https://stackoverflow.com/q/51068247/11107541 – starball Jul 04 '23 at 05:42

1 Answers1

1

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
Daniil Loban
  • 4,165
  • 1
  • 14
  • 20