How to fix/convert space indentation in Sublime Text?

后端 未结 9 1168
梦谈多话
梦谈多话 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:53

    The easiest thing i did was,

    changed my Indentation to Tabs

    and it resolved my problem.

    You can do the same,

    to Spaces

    as well as per your need.

    Mentioned the snapshot of the same.

    0 讨论(0)
  • 2020-11-30 16:56

    I found, in my mind, a simpler solution than Magne:

    On mac:

    "cmd+f" => "  "(two spaces) => "alt+enter" => "arrow right" => "  "(two more spaces) => set tab width to 4(this can be done before or after.
    

    On windows or other platforms change cmd+f and alt+enter with whatever your find and select all hotkeys are.

    Note: this method is prone to "errors" if you have more than one space within your code. It is thus less safe than Magne's method, but it is faster (for me at least).

    0 讨论(0)
  • 2020-11-30 16:56

    While many of the suggestions work when converting 2 -> 4 space. I ran into some issues when converting 4 -> 2.

    Here's what I ended up using:

    Sublime Text 3/Packages/User/to-2.sublime-macro

    [
      { "args": null, "command": "select_all" },
      { "args": { "set_translate_tabs": true }, "command": "unexpand_tabs" },
      { "args": { "setting": "tab_size", "value": 1 }, "command": "set_setting" },
      { "args": { "set_translate_tabs": true }, "command": "expand_tabs" },
      { "args": { "setting": "tab_size", "value": 2 }, "command": "set_setting" }
    ]
    
    0 讨论(0)
提交回复
热议问题