ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Tab​To​Space​Converter

by maliayas ST3

Convert tabs to spaces in Sublime Text and preserve inline alignments.

Details

Installs

  • Total 844
  • Win 437
  • Mac 229
  • Linux 178
Apr 27 Apr 26 Apr 25 Apr 24 Apr 23 Apr 22 Apr 21 Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14
Windows 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 1 0 0 0 0 0 0 0
Mac 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0
Linux 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0

Readme

Source
raw.​githubusercontent.​com

TabToSpaceConverter

TabToSpaceConverter is a Sublime Text plugin that converts tab characters in a file to spaces and applies your new tab width setting to it; while preserving tab based inline alignments.

Batch converting is supported.

Overview

The Problem

Let's say you have a file that uses hard tabs for indendation and for inline alignment:

image-1

And the above file is created with tab_size = 8 setting, so the inline alignment only works when the tab_size is 8.

And then you want to adapt the file to a different styleguide, which uses 4 spaces for indentation. When you open the file with the new settings, you will see:

image-2

To apply the new styleguide to the file, you would normally use the Sublime Text menu in the status bar (Convert Indentation to Spaces):

menu

Which would give you the below result, breaking the inline alignment:

image-3

The Solution

Use this plugin and get the below result, as you would expect:

image-4

Installation

You can install the plugin via:

  • Package Manager by searching TabToSpaceConverter
  • git clone https://github.com/maliayas/SublimeText_TabToSpaceConverter.git TabToSpaceConverter
  • Downloading the zip of the repo and extracting into Packages/TabToSpaceConverter

The plugin is developed for Sublime Text 3 and above. It's not tested on Sublime Text 2; however it may still work there, so you can give it a try if you have to.

Usage

This plugin is meant to be used with a keybinding. It's not defined by default, because it needs some configuration. You should click the Preferences > Key Bindings menu and then add a keybinding like this:

{
    "keys"      : ["ctrl+alt+t"],
    "command"   : "tab_to_space_converter",
    "args"      : {"previous_tab_size": 8, "all_views": false}
}
  • previous_tab_size: In order the plugin to preserve inline alignments, it has to know what tab_size setting was used when the file was created.

  • all_views: If you set this to true, all the open views will be converted. To save all those files, you can use the File > Save All menu.

You don't have to provide your current tab_size setting to the plugin, just set it in the Sublime Text and the plugin will read it.

Similar Plugins

Other plugins that are similar to this one (they don't do the same task though):

License

TabToSpaceConverter is released under the MIT License.