Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force Sublime Text to indent two spaces per tab?

Is there a way to force Sublime Text 2 to always indent two spaces per tab when working with Ruby files?

I know that indentation can be set under the view -> indentation menu option, but it does not stick. Every time I open a new file and hit tab, it reverts back to four spaces.

like image 977
Mohamad Avatar asked Feb 27 '12 23:02

Mohamad


People also ask

How do I indent automatically in Sublime Text?

That's quite simple in Sublime. Just Ctrl+Shift+P (or Command+Shift+P on MacOS) to open the tools pallet, type reindent , and pick Indentation: Reindent Lines . It should reindent all the file you are in, just remember to save before running the command, or it may not appear.

How do you change the tab indent to 4 spaces sublime?

To configure the tab width in Sublime Text 3, click on “View” in the top bar, then click on “Indentation” in the drop-down list. Next, in the second level of the drop-down list select the width you want a tab to take up. Sublime Text 3 defaults to tabs being four spaces wide.

How do I indent multiple lines in Sublime Text?

You can use ctrl+ ] to indent a line (or highlighted block), and ctrl + [ to unindent. On OSX this is cmd + ]/[ . at least on the mac version tab & shift-tab work on whole lines and the position of the cursor has no influence on it.

How do I fix sublime spacing?

by pressing ctrl+f12, it will reindent your file to a tab size of 4. if you want a different tab size, you just change the "value" number.

How to convert indentation spacing to tabs in Sublime Text?

Here's a neat trick in Sublime Text 2 or 3 to convert your indentation spacing in a document. Ensure tab width is set to 2. Convert your 2-space indentation to tabs, switch to tab width 4, and then convert the indentation back to spaces. The detailed description: Done. Show activity on this post.

How to convert indentation to spaces in Microsoft Word?

You can see that those Tabs are 2 spaces wide. Assuming I want to switch to spaces and I’m happy with 2 spaces per tab, I just select “Convert Indentation To Spaces” from that menu. And I’m good to go for that case. Let’s say a straight conversion from tabs to spaces isn’t going to do it for me.

Is indentation sticky in Sublime Text?

It's a good tip, but it's not sticky: closing and reopening the file (or opening another file) reverts indentation to four spaces. – Mohamad Apr 15 '14 at 15:11 1 Yeah, it is not sticky, it's per file. You have to go to into the settings of Sublime Text to setup your default setting for tabs/spaces. – Taskism May 28 '14 at 22:03

Is it possible to add tabs in Sublime Text?

Yeah, it is not sticky, it's per file. You have to go to into the settings of Sublime Text to setup your default setting for tabs/spaces. – Taskism May 28 '14 at 22:03 This resolved my issue in Sublime Text 3. Thank you! – Adrian May 7 '16 at 23:44 Add a comment | 34 Can I suggest EditorConfig?


1 Answers

If you want it for all files, go to Preferences -> Settings - Default/User. But as several comments below indicate, Syntax Specific settings can limit it to just the languages you choose.

To limit this configuration to Ruby files, first open up a Ruby file in the editor, and then go to Preferences -> Settings - Syntax Specific. This should open a settings window named Ruby.sublime-settings

Save these settings:

{   "tab_size": 2,   "translate_tabs_to_spaces": true,   "detect_indentation": false } 

Repeat for any other syntax types by opening a file of that type and going back to the preferences to open the correct preferences file for that syntax.

I have edited this to include the "detect_indentation" line per the requests in comments; I previously used the Default/User to set my tab size, and have not needed the tab detection, but whether that is due to the global config or due to the fact that I have rarely opened files with tabs, I do not know.

Restarting should not be necessary, although in some instances it can be.

like image 199
DGM Avatar answered Oct 18 '22 22:10

DGM