Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text Indentation Settings Being Overwritten By a File

I am working on a project where tab size is supposed to be 4 and tabs should not be spaces. I updated my Preferences.sublime-settings file to include

"detect_indentation": "false",
"tab_size": 4,
"translate_tabs_to_spaces": false,

When I open a new file these settings are set to how I want and everything works. However, if I open an existing file (scss or html) that has indentations as 2 spaces, my Sublime settings are overwritten and indentations change to 2 spaces. If I click View > Indentation I see that Tab Size is set to 2 and Indent Using Spaces is enabled, even though my preferences should be the opposite of that.

If I manually change Indentation via View > Indentation to Tab Width: 4 and deselect Indent Using Spaces, this works until I save the file, at which point the settings revert to Tab Width 2 and Indent Using Spaces turned on.

How can I force Sublime Text to honor my indentation preferences and not be overwritten by another file. I would assume that Sublime is detecting the indentations on the page, but I've turned that setting off.

Here is my preferences file showing that things should be working:

preferences file

Here are the messed up settings for a scss file. All I did was open it:

incorrect indentation settings

I don't think any plugin is causing this, I disabled most of them and was still experiencing this issue. However, for reference, here is a list of all packages I have installed:

  • Alignment
  • BracketHighlighter
  • Capybara Snippets
  • ColorPicker
  • Dotfiles Syntax Highlighting
  • EditorConfig
  • Emmet
  • ERB Snippets
  • Gem Browser
  • Gist
  • Git
  • GitGutter
  • Haml
  • jQuery
  • JSHint
  • Package Control
  • Pretty JSON
  • PyV8
  • RSpec
  • SCSS
  • SideBarEnahancements
  • SublimeLinter
  • Terminal
  • TrailingSpaces

Thanks in advance for any help.

like image 348
jasonleibowitz Avatar asked Feb 13 '15 17:02

jasonleibowitz


2 Answers

So I figured this out by completely uninstalling Sublime Text and all associated packages and settings, then reinstalling the app and one-by-one reinstalling my packages. It turns out that one of my packages, EditorConfig, was overwriting my Sublime Text style settings.

EditorConfig is actually a really cool plugin that allows a number of developers working on one project across multiple IDEs to have a consistent style by defining indentation type, size, charset, and other settings.

The answer to my problem was that in the particular project directory I was working some of the node modules I had downloaded had .editorconfig files that had indentation set as size 2 and spaces instead of tabs. I had to either uninstall the EditorConfig package from my Sublime Text or create a new .editorConfig file in the root directory of my project. This is the .editorConfig file I created that fixed my problem.

# top-most EditorConfig file
root = true

# 4 Tab Indentation
indent_style = tab
indent_size = 4
like image 139
jasonleibowitz Avatar answered Nov 09 '22 12:11

jasonleibowitz


When a file is loaded, its contents are examined, and the "tab_size" and "translate_tabs_to_spaces" settings are set for that file. The status area will report when this happens. While this generally works well, you may want to disable it. You can do that with the "detect_indentation" setting.

This might be helpful: https://www.sublimetext.com/docs/2/indentation.html

like image 35
BarzinM Avatar answered Nov 09 '22 14:11

BarzinM