How to fix/convert space indentation in Sublime Text?

后端 未结 9 1177
梦谈多话
梦谈多话 2020-11-30 15:59

Example: If I have a document with 2 space indentation, and I want it to have 4 space indentation, how do I automatically convert it by using the Sublime Text editor?

9条回答
  •  一整个雨季
    2020-11-30 16:52

    I actually found it's better for my sanity to have user preferences to be defined like so:

    "translate_tabs_to_spaces": true,
    "tab_size": 2,
    "indent_to_bracket": true,
    "detect_indentation": false
    

    The detect_indentation: false is especially important, as it forces Sublime to honor these settings in every file, as opposed to the View -> Indentation settings.

    If you want to get fancy, you can also define a keyboard shortcut to automatically re-indent your code (YMMV) by pasting the following in Sublime -> Preferences -> Key Binding - User:

    [
      { "keys": ["ctrl+i"], "command": "reindent" }
    ]
    

    and to visualize the whitespace:

    "indent_guide_options": ["draw_active"],
    "trim_trailing_white_space_on_save": true,
    "ensure_newline_at_eof_on_save": true,
    "draw_white_space": "all",
    "rulers": [120],
    

提交回复
热议问题