Greg
Greg

Reputation: 93

Convert formatting tabs to spaces in VS Code

Before someone tries to mark this as a duplicate, DON'T. Please read the question very carefully. I've seen similar questions asked (and answered incorrectly).

I am using Visual Studio Code. I have code that has used tabs WITHIN A LINE, not just at the beginning, to format columns. I am trying, unsuccessfully, to convert those tabs to the appropriate number of spaces to maintain the columns.

Before you suggest ctrl-shift-I, that only works on LEADING tabs, not those within the line. Also, don't suggest the "Untabify" or similar extensions. Those only convert every tab to 4 (or however many) spaces without determining how many spaces would be appropriate to maintain the tab stops.

Visual Studio 2008 had an "untabify" function that would do exactly what I am looking for. It doesn't seem to have been carried over to VSCode.

Thanks, Greg Thanks.

Upvotes: 9

Views: 8271

Answers (4)

Glops
Glops

Reputation: 91

Another solution which does not involve an extension:

  1. Convert your file to space indentation using the command "Convert to space indentation". It will change all the tabs at the beginning of the lines to space.
  2. Select one of the remaining tab, press ctrl+shift+L to select all occurences.
  3. Press tab. All the tabs should be replaced with the correct number of spaces.

Upvotes: 9

Hiroo
Hiroo

Reputation: 54

None of "untabify" extension do not work as I expect. "Edit with Shell Command" extension with "expand" command works.

Upvotes: 2

Manfred Wuits
Manfred Wuits

Reputation: 175

in the meantime, someone created the extension which solves your problem:

https://github.com/dmfabritius/untabify

Upvotes: 3

user12251171
user12251171

Reputation:

Do a search for Regex's \t and replace with your wanted number of spaces?

enter image description here

Upvotes: -2

Related Questions