Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 381
Greg Avatar asked May 19 '26 20:05

Greg


1 Answers

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.
like image 80
Glops Avatar answered May 22 '26 13:05

Glops



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!