如何強制Sublime Text每個標籤縮進兩個空格?

本文翻譯自: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? 有沒有辦法強制Sublime Text 2在使用Ruby文件時始終每個標籤縮進兩個空格?

I know that indentation can be set under the view -> indentation menu option, but it does not stick. 我知道縮進可以在view -> indentation菜單選項下設置,但它不會粘。 Every time I open a new file and hit tab, it reverts back to four spaces. 每次我打開一個新文件並點擊標籤時,它都會恢復爲四個空格。


#1樓

參考:https://stackoom.com/question/dkdu/如何強制Sublime-Text每個標籤縮進兩個空格


#2樓

If you want to force your chosen tab setting, ignoring what's likely already going on in the file, then you should include detect_indentation in your configuration (your User settings or your Syntax Specific settings, depending on if you want it global or per-filetype): 如果您想強制選擇的選項卡設置,忽略文件中可能已經發生的事情,那麼您應該在配置中包含detect_indentation (您的用戶設置或語法特定設置,具體取決於您是希望全局還是每個文件類型) :

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

#3樓

You can also do this with the text link in the bottom bar of Sublime Text 2 ( On the right side ) that says "Tab Size 4" by default, click that and a window comes up with options to set the tab size from 1 space all the way up to 8 spaces and includes options to convert tabs to spaces and spaces to tabs. 您也可以使用Sublime Text 2(右側)底欄中默認顯示“Tab Size 4”的文本鏈接,單擊該文本鏈接,然後在窗口中顯示從1個空格設置選項卡大小的選項一直到8個空格,包括將標籤轉換爲空格和空格到標籤的選項。

Looks like this: 看起來像這樣:

Sublime Text 2中的選項卡選項


#4樓

Can I suggest EditorConfig ? 我可以推薦EditorConfig嗎? There is an extension to autoload and apply the .editorconfig file. 自動加載有一個擴展並應用.editorconfig文件。 Then just create one in the root of your project. 然後只需在項目的根目錄中創建一個。

.editorconfig

[*.rb]
indent_style = tab
indent_size = 2

This way, your settings are project-specific and file-specific if you use different styles for each project or language. 這樣,如果爲每個項目或語言使用不同的樣式,則您的設置是特定於項目和特定於文件的。


Here is what my own .editorconfig looks like. 這是我自己的.editorconfig看起來像。

# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

#5樓

I followed the previous answers, including adding the detect_indentation line, and my tabs were still five spaces. 我按照之前的答案,包括添加detect_indentation行,我的標籤仍然是五個空格。 Then I realized that selecting Preferences -> Settings -> More -> Syntax Specific -> User from a ruby file was opening up Ruby on Rails.sublime-settings for me, not Ruby.sublime-settings . 然後我意識到從ruby文件中選擇Preferences -> Settings -> More -> Syntax Specific -> User爲我打開了Ruby on Rails.sublime-settings ,而不是Ruby.sublime-settings

I renamed my Ruby on Rails.sublime-settings file to Ruby.sublime-settings . 我將Ruby on Rails.sublime-settings文件重命名爲Ruby.sublime-settings Finally two-space tabs worked! 最後兩個空格標籤工作! I went ahead and put the same settings in Ruby on Rails.sublime-settings as well, just to be sure. 我繼續在Ruby on Rails.sublime-settings相同的設置,只是爲了確定。


#6樓

I use Stupid Indent package. 我使用Stupid Indent包。

Install Package -> Stupid Indent Install Package - > Stupid Indent

Preferences -> Package Settings -> Stupid Indent -> Setting-Users Preferences - > Package Settings - > Stupid Indent - > Setting-Users

Copy settings (of Ruby part) into. 將設置( Ruby部分)複製到。

{
    "configuration":
    [
        {
            "patterns": ["*.rb"],
            "tab_size": 2,
            "translate_tabs_to_spaces": true
        }
    ]
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章