Sublime Forum

Insert TAB characters, but indent using spaces

#1

I like to indent code using spaces, but sometimes I want to insert a literal TAB character in the middle of the line. Is there some way to configure Sublime for this behaviour?

3 Likes

#2

The only way I know of is to turn off “translate spaces to tabs”, hit tab, then turn it back on. If you really wanted you could write a plugin to run these three steps in sequence.

2 Likes

#3

Looking at the default settings you’ll find the following entry:

// By default, shift+tab will only unindent if the selection spans
// multiple lines. When pressing shift+tab at other times, it'll insert a
// tab character - this allows tabs to be inserted when tab_completion is
// enabled. Set this to true to make shift+tab always unindent, instead of
// inserting tabs.
"shift_tab_unindent": false,

HTH

1 Like

#4

Unfortunately the tab that shift+tab inserts is still translated to spaces like any other tab.

1 Like

#5

If @adzenith 's advice works (I didn’t test it), it should be very easy to create a macro with the three commands (rather than messing with python, if you don’t want to), which you can then invoke by a keybinding, menu item or command in the palette.

Hope this helps,
Alex

1 Like

#6

What I end up doing in these cases, where I don’t want to be bothered with toggling the setting, is to insert some odd character (like a backtick) into the doc where I want tabs, and then do a find/replace, replacing the backtick with \t (regex tab). This allows me to sneak the tab(s) in there.

1 Like

#7

What about adding a keybinding that inserts the snippet “\t”?

1 Like

#8

+1
I use spaces for indentation, but I occasionally use the ElasticTabstops plugin to format tables of data.
So I’d like the Tab key to enter spaces at the beginning of the line, but a literal tab when used in the middle of a line of text.
Has anybody written a plugin to do this?

1 Like

#9

6 years later the recipe is emerged (at least for Windows, ST4).

  1. (Indent Using Spaces initially enabled) enter the sequence (4 keys) Alt, v, i, i
    • this will disable Indent Using Spaces
  2. Input tab characters using Tab key
  3. Reenable Indent Using Spaces by entering the same sequence again (Alt, v, i, i)
0 Likes

#10

This may also be use:

https://stackoverflow.com/a/45601124/814803

0 Likes