How can I convert tabs to spaces and vice versa in an existing file
I cannot figure out how to do this for the life of me apart from doing a find-replace on 4 spaces and converting to tabs (Version 0.10.2). I can't think of an editor/IDE that doesn't have a specific feature to do this. Does VSCode?
Since fix of: https://github.com/Microsoft/vscode/issues/1228 the editor supports it out of the box. Simply go for:
-
F1
, -
indentationToSpaces
orindentationToTabs
(depending on your need) -
Enter
.
Another way to do it is click the current indentation (Tab/Spaces:n) on the footer which will open your indentation options where you can select what you want to do.
If you are trying to convert non-leading tabs to spaces (or vice versa) you can use a regex search and replace.
- Press CTRL + H
- Click the
.*
button to search using regular expressions. - To search for tabs enter
[\t]
in Find box. - Enter spaces in Replace box and perform your replace.
Search box in regex mode: