Home Download Buy Blog Forum Support

Insert TAB characters, but indent using spaces

Insert TAB characters, but indent using spaces

Postby dserodio on Fri Feb 22, 2013 5:46 pm

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?
dserodio
 
Posts: 8
Joined: Mon Oct 24, 2011 1:05 pm

Re: Insert TAB characters, but indent using spaces

Postby adzenith on Fri Feb 22, 2013 6:25 pm

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.
adzenith
 
Posts: 1213
Joined: Mon Oct 19, 2009 9:12 pm

Re: Insert TAB characters, but indent using spaces

Postby Stefano.Rausch on Fri Feb 22, 2013 9:37 pm

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
Stefano.Rausch
 
Posts: 29
Joined: Thu Feb 14, 2013 5:05 pm

Re: Insert TAB characters, but indent using spaces

Postby adzenith on Sun Feb 24, 2013 1:20 pm

Unfortunately the tab that shift+tab inserts is still translated to spaces like any other tab.
adzenith
 
Posts: 1213
Joined: Mon Oct 19, 2009 9:12 pm

Re: Insert TAB characters, but indent using spaces

Postby quodlibet on Mon Feb 25, 2013 2:17 pm

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
quodlibet
 
Posts: 498
Joined: Sat Jun 18, 2011 5:53 pm

Re: Insert TAB characters, but indent using spaces

Postby frogsmock on Mon Apr 22, 2013 4:41 pm

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.
frogsmock
 
Posts: 1
Joined: Mon Apr 22, 2013 4:37 pm

Re: Insert TAB characters, but indent using spaces

Postby FichteFoll on Tue Apr 23, 2013 7:31 pm

What about adding a keybinding that inserts the snippet "\t"?
FichteFoll
 
Posts: 377
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot] and 14 guests