vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Add option to convert tabs to spaces

Open pcgeek86 opened this issue 10 years ago • 24 comments

Would it be possible to add a VS Code command to convert tabs to spaces, and vice versa?

I copied some JSON code from GitHub into VS Code, using Google Chrome, and it's indented using tabs. I'd like to convert it to use 2 spaces.

I searched for this issue on here, and couldn't find it. I only saw references to VS Code settings for using tabs or spaces by default.

Cheers, Trevor Sullivan Microsoft MVP: PowerShell

pcgeek86 avatar Dec 13 '15 15:12 pcgeek86

This can be fairly easily achieved using find and replace with regex. This sort of functionality would probably better be captured in an extension rather than the core editor.

Tyriar avatar Dec 13 '15 21:12 Tyriar

I agree with @Tyriar.

hashhar avatar Dec 13 '15 22:12 hashhar

+1 that this is should be done in an extension. Keeping open as a help wanted, feature request.

egamma avatar Dec 14 '15 07:12 egamma

I do agree that this can be done via an extension, however, I strongly believe that a simple option to translate tabs to spaces or vice versa should be present as it increases the editor's usability a lot. The developer's focus would remain on the code rather than on fixing such trivial issues by searching for an extension. These convenient yet lightweight additions to the editor would make it really pleasing to use.

It was one of the features of Sublime Text that I clearly remember being handy when required!

Tabs to Spaces

xeoneux avatar Dec 14 '15 12:12 xeoneux

Looks like there are a couple of extensions that do this.

  • https://marketplace.visualstudio.com/items/yuichinukiyama.TabSpacer
  • https://marketplace.visualstudio.com/items/ilich8086.Untabify

waderyan avatar Dec 16 '15 23:12 waderyan

@xeoneux I agree, this should be on the core editor.

suederade avatar Dec 22 '15 21:12 suederade

+1 (I m currently copy pasting tabs)

bumpmann avatar Jan 17 '16 18:01 bumpmann

It can be an extension, sure. But VS Code already does so many neat things that ease development (like Git integration) which are extensions on other editors. This could easily be a built-in feature.

andradei avatar Jan 22 '16 19:01 andradei

+1

warpdesign avatar Jan 27 '16 12:01 warpdesign

+1 for this feature built into vscode

gulshan avatar Jan 28 '16 05:01 gulshan

+1

jcurlier avatar Jan 28 '16 06:01 jcurlier

+1

perrich avatar Jan 28 '16 07:01 perrich

Things like tab/space and line ending conversion is really a core editor feature in my mind.

evolutional avatar Jan 28 '16 09:01 evolutional

The primary reason I switched from Atom to Code was that I would no longer need to install an extension for every little editor feature I used daily. To me, space / tab conversion is a fundamental code editing requirement that belongs in the core product.

LittleBrainz avatar Jan 28 '16 09:01 LittleBrainz

@LittleBrainz Exactly. Code provides a lot of functionality out of the box as compared to Atom and that was my reason for the switch too.

xeoneux avatar Jan 28 '16 10:01 xeoneux

+1

When opening "foreign" files a simple core option would be much better than ext replace or beeing forced to install an extension

cthedot avatar Jan 28 '16 11:01 cthedot

:+1: and spaces to tabs please

rakkarage avatar Jan 28 '16 16:01 rakkarage

+1

fcrespo82 avatar Jan 28 '16 20:01 fcrespo82

+1

I use Untabify but agree that this should be a core feature.

allbitsnbytes avatar Jan 29 '16 00:01 allbitsnbytes

There is an extension I created a while back that achieves this, it automatically updates files on save so if you touch the file it will normalize the whitespace.

  • Marketplace: https://marketplace.visualstudio.com/items?itemName=sandcastle.whitespace
  • GitHub: https://github.com/sandcastle/vscode-whitespace

sandcastle avatar Jan 29 '16 01:01 sandcastle