Change tabs to spaces


#1

There should be an option to convert all tab characters to white-space. I had thought that the “tabLength” would do this but it basically only applies to tabs itself and not allowing the editor to output white-space instead of tabs.

Edit: Found out the option is called “softTabs” and it is enabled by default which will be hidden in the CSON file when it is disabled which was a bit confusing.


#2

There’s still no “Convert Tabs to Spaces” kind of thing, right? I see the option for soft tabs, but it doesn’t convert my documents unfortunately.


#3

I’m surprised to see that this isn’t available.


#4

Give me a sec … whipping up a package now.


#5

Here you go:

It is very bare bones. It doesn’t have a keymap (you can add your own), but it does show up in the Packages menu, in the context menu in an editor window and in the command palette. It uses your editor.tabLength property to decide how many spaces to replace a tab with. It should only replace leading tabs … but I have only tested it on two files.

If you have issues or suggestions, let me know! :smile:


Tabs to Spaces Package
#6

Thanks so much Lee, awesome stuff.


#7

If you select all the lines and Edit > Lines > Auto Indent it should convert between tabs/spaces.


#8

Auto Indent didn’t work for me mate but Lee’s package did the trick the time this feature gets implemented :smiley:
Thanks Lee!


#9

You’re all welcome. I’m glad I could help!


#10

@leedohm I installed the plugin, it works well as it advertised. But I prefer to code everything in tab instead of spaces. Are you going to add a feature on toggle spaces or tabs. or make it switch spaces to tabs.

Another question, unlike sublime, if I highlight the text (ex: test.sass), it does not show it is tab or space (ex: spaces will draw some dots). I tried to turn on the toggle soft wrap, it did not work either.

I have a config setting like this

  'softWrap': false
  'softWrapAtPreferredLineLength': false
  'showInvisibles': false

#11

@mattma Yes, one of the things I’m working towards adding is the “tabify” command, converting leading spaces to tabs.

There is a thread here on showing “invisibles” (visualizations of whitespace characters) only on highlight:

If you want to show invisibles full time, I use the following:

'editor':
  'showInvisibles': true
  'invisibles':
    'cr': '↩'
    'eol': ''
    'space': '·'
    'tab': '⇥'

And in my personal stylesheet I have:

@hints-color: #c5c8c6;
@hints-opacity: 0.3;

.editor {
  .invisible-character {
    color: @hints-color;
    opacity: @hints-opacity;
  }
}

I use a dark UI and stylesheet, so you may need to adjust the coloring and opacity for your situation.


#12

@lee​dohm I do use dark ui too. So those snippets work out of the box. That is exactly what I am looking for. Thanks a lot for your time.

Does you have a timeline on when tabify is going to be done? I thought that if you are able to convert tab to spaces, then you should just revert the logic for spaces to tab. I am totally making a wild guess. In the real life, it should be much more complicated than that.

tab-to-spaces 0.2.0, did you just push the latest? does it include the tabify?


#13

Yep … release notes:


#14

I moved a post to an existing topic: Tabs to Spaces Package


#15

how does one change the configs for this?