16

I would like change the basic indentation on template ruby haml. He is set when I create a new file to 'Tab Size: 4' How change it in 'Spaces: 2'?

Thanks.

Guillaume
  • 325
  • 2
  • 4
  • 16
  • 2
    Flagged as a duplicate for [this](http://stackoverflow.com/questions/9474090/how-do-i-force-sublime-text-2-to-use-two-spaces-per-tab) as the other more recent question was phrased a bit more clearly and had more votes/an easier solution. – iono Nov 21 '12 at 07:56
  • possible duplicate of [Indenting code in Sublime text 2?](http://stackoverflow.com/questions/9495007/indenting-code-in-sublime-text-2) – Lucio Oct 04 '14 at 20:56

3 Answers3

22

To change the indentation settings just for ruby files create a new file named Ruby.sublime-settings, based on your OS, in %APPDATA%\Sublime Text 2\Packages\User or ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/ or ~/.config/sublime-text-2/Packages/User/' with the following content:

{
  // The number of spaces a tab is considered equal to
  "tab_size": 2,

  // Set to true to insert spaces when tab is pressed
  "translate_tabs_to_spaces": true
}
dsander
  • 373
  • 1
  • 6
  • 1
    This should be reflected in the original Ruby Package. – jiggysoo Jun 14 '12 at 20:14
  • 7
    While this answer works fine - thanks! - I just noticed a duplicate question [here](http://stackoverflow.com/questions/9474090/how-do-i-force-sublime-text-2-to-use-two-spaces-per-tab) that has an easier way to create/edit the Ruby-specific settings file: ```Preferences -> Settings -> More -> Syntax Specific -> User``` – iono Nov 21 '12 at 07:52
10

There is a better and easier way to set the indentation. To change indentation for all file types go to:

Preferences -> Settings - Default/User

To change indentation for a specific file type, open a file type of your choice in the editor, and then go to:

Preferences -> Settings -> More -> Syntax Specific -> User

In both cases Sublime Text will open a file called Ruby.sublime-settings. Save the following settings:

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

You can read more about this in this SO question.

Community
  • 1
  • 1
Mohamad
  • 32,727
  • 31
  • 131
  • 208
5

To change indentation within the document, go to View > Indentation > Convert Tabs to Spaces. To make this change within the document for future edits, go to View > Indentation > Spaces Width: 2. Additionally, if you have the status bar visible, you can you can click where it says Tab Size: 4 and change the indentation here from the context menu.

BoundinCode
  • 13,183
  • 5
  • 37
  • 29
  • 1
    My goal isn't just change to one file the indentation. But change the basic settings to all ruby files. Thanks. – Guillaume Feb 23 '12 at 16:06