Sublime Forum

Tabbing to tab stops in Typescript with ST3

#1

I’m new to Sublime. I just want the tab to take the cursor to the next tab stop, inserting spaces to that point. Ideally, I also want hitting delete from a tab stop to take me to the previous tab stop.

I get this behavior in an empty file. When I save a file as .ts or .js, hitting tab instead inserts 4 spaces no matter where the cursor is. Even in a brand new file. Hitting delete never back-tabs.

How do I fix this? My settings:

"tab_size": 4,
"translate_tabs_to_spaces": true, // true or false, doesn't make a difference
"use_tab_stops": true,
"shift_tab_unindent": true, // true or false, doesn't make a difference
"detect_indentation": true,
"auto_indent": true,
"smart_indent": true,

CLARIFICATION: I want to insert spaces, not tabs. I am now only seeing this problem in Typescript, not Javascript, though I thought I also tested in JS when I posted this.

0 Likes

#2

Hello? Is there another way to get help? Thanks!

0 Likes

#3

If you have a js/ts file open, on the bottom right there should be a drop down menu with the label “Spaces: 4”. Open it and check that “Indent using Spaces” is disabled.

0 Likes

#4

Disabling it fixed the problem for just that one file, but then I can’t cursor through the tabbed area, suggesting that it inserted a tab character and not spaces.

I’m used to editors having this behavior while inserting spaces for tabs (e.g. BBedit and Visual Studio Code). Is this not possible in Sublime?

Thanks for responding!

0 Likes

#5

For some reasons you have set "translate_tabs_to_spaces": true inside js/ts files, but you need to change it to "translate_tabs_to_spaces": false. If I understand you correctly you already tried to change it in the User settings. You may try to open Preferences > Settings - Syntax Specific while being inside a ts file and add the setting there (this has something to do with setting precedences).

0 Likes

#6

That didn’t help. I now have the following in TypeScript.sublime-settings, but there’s no change in behavior. Closing and reopening the file didn’t help either. Closing and reopening Sublime also didn’t change anything.

{
    "translate_tabs_to_spaces": true
}

Maybe I should file a bug report? Hard to believe I’d be the first to encounter this.

0 Likes

#7

It should be false, you want to insert tabs and not spaces.

0 Likes

#8

I want to insert spaces, not tabs.

Turns out that the problem only exists in Typescript files, not Javascript files. I recall trying it in JS earlier but can’t reproduce the problem there.

Since we may be talking past each other, here is what I’m trying to do:

  • Insert spaces when I tab.
  • Have the tab take me to the next tab stop, despite inserting spaces.
  • Hitting delete from a tab stop preceded only by spaces takes the cursor back one tab stop.

I’m getting the first but not the latter two in Typescript.

0 Likes

#9

Open the ST console and write sublime.log_commands(True) and check which commands are executed when you press tab and backspace (?).

Do you have a typescript package installed?

0 Likes

#10

Okay, I’ll try that. But first, I discovered this issue with the Typescript plugin, which I do have installed. They’re blaming Sublime for not providing them with the information they need:

0 Likes

#11

Tab (4 chars to next tab stop): reindent
Space + tab (3 chars to next tab stop): insert_best_completion {“default”: “\t”, “exact”: false}
Backspace from where it should unindent: left_delete

0 Likes

#12

I disabled the typescript package, but I still have the problem. Maybe because it’s no longer treating it as code? I also no longer get syntax highlighting, so I’m not happy to do without.

0 Likes

#13

They seem to disable it in the package, because it results in problems for their features and the package ships the syntax highlighting. If you are only missing the syntax highlighting (and not features like code completion etc.) you can just download it here and put it into your ST user folder (i.e. open Preferences > Browse Packages… and then the User folder).

0 Likes

#14

Excellent! THANK YOU! That suits me perfectly.

I’ve been gradually disabling TS plugin features for finding them flaky. Syntax highlighting is all I need. If I want in-editor linting, I can switch over to Visual Studio Code last minute to clean things up.

0 Likes

#15

For anyone else who bumps into this thread, the correct syntax highlighting files are found in another repo (limited to two links, so no link to the repo):

0 Likes