Sublime Forum

Convert Indentation to Tabs doesn't work

#1

Convert Indentation to Tabs doesn’t work. Vice verse operation (Convert Indentation to Spaces) works fine, but Indentation to Tabs doesn’t.
Is this a bug? Any ideas how to fix it?

Usecase.
I have a config file with Space indention. I want to convert all Spaces to Tabs. I select all the content in the file Ctrl+A, then select menu option (see screenshot) and nothing happens. Indentation remains spaces

Build: 3126
OS: Windows 10 Pro 64

0 Likes

#2

are you able to share the file that it doesn’t work on, please?

are there any errors in the ST console?

0 Likes

#3

Why console? I don’t use console to convert indentation, so can’t tell you.

How can I attach a file here? Upload option is for images only, it doesn’t accept my file.

However here is a screenshot. First three rows are tabs. They are from PayPal sample file. The rest two lines I typed manually and they have spaces (my ST setting is Tab to Space and Tab size: 4; So when I hit Tab, I get 4 spaces). And those spaces cannot be converted to tabs automatically with ST’s option.

File is saved with UTF-16 LE with BOM if anything

0 Likes

#4

because the Convert Indentation to Tabs menu item executes a Python command behind the scenes, called unexpand_tabs, and if there is an exception executing the code, it will show in ST’s console (View menu -> Show Console), which can help identify the problem.

0 Likes

#5

ah, I can replicate the problem:

  1. open a new tab
  2. make sure “indent using spaces” is not ticked
  3. type abc Tab def Tab ghi Enter
  4. make sure “indent using spaces” is ticked
  5. type hello Tab world Tab test Enter
  6. select all
  7. convert indentation to tabs
  8. nothing happens

same happens with only 2nd line selected

but I think it is to be expected - convert indentation to tabs refers to whitespace before the first non-whitespace character on the line

of course, if you are typing lines manually and want tabs, you could ensure “indent using spaces” is not ticked before doing so

0 Likes

#6

Nope. The operation itself (Convert Indentation to Tabs) doesn’t throw anything. But when I focus mouse cursor in the tab with code and press mouse button, this is what is thrown in console:

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 389, in run_callback
    expr()
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 522, in <lambda>
    run_callback('on_activated', callback, lambda: callback.on_activated(v))
  File "trailing_spaces in C:\Users\user\AppData\Roaming\Sublime Text 3\Installed Packages\TrailingSpaces.sublime-package", line 419, in on_activated
  File "trailing_spaces in C:\Users\user\AppData\Roaming\Sublime Text 3\Installed Packages\TrailingSpaces.sublime-package", line 440, in freeze_last_version
  File "./python3.3/codecs.py", line 691, in read
  File "./python3.3/codecs.py", line 494, in read
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
0 Likes

#7

if you want to convert all spaces to tabs, not just indentation, you could use:

  1. Find menu -> Replace…
  2. Ensure Regex mode is enabled
  3. Find What: [ ]+
  4. Replace With: \t
  5. Replace All
1 Like

#8

as for the TrailingSpaces error, you may want to report it at https://github.com/SublimeText/TrailingSpaces/issues if an issue doesn’t already exist for it. Probably it doesn’t cope with your UTF-16 LE with BOM encoding.

0 Likes