Sublime Text 3, convert spaces to tabs

前端 未结 11 2253
[愿得一人]
[愿得一人] 2020-12-07 08:07

I know there are a lot of posts about this, but I couldn´t get it to work.
I use tabs for coding. Is there a way, to convert always spaces to tabs? I.e. on open and on S

相关标签:
11条回答
  • 2020-12-07 08:55

    You can use the command palette to solve this issue.

    Step 1: Ctrl + Shift + P (to activate the command palette)

    Step 2: Type "Indentation", Choose "Indentation: Convert to Tabs"

    0 讨论(0)
  • 2020-12-07 08:55

    if you have Mac just use help option (usually the last option on Mac's menu bar) then type: "tab indentation" and choose a tab indentation width

    but generally, you can follow this path: view -> indentation

    0 讨论(0)
  • 2020-12-07 09:00

    As you might already know, you can customize your indention settings in Preferences.sublime-settings, for example:

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

    This will set your editor to use tabs that are 4 spaces wide and will override the default behavior that causes Sublime to match the indention of whatever file you're editing. With these settings, re-indenting the file will cause any spaces to be replaced with tabs.

    As far as automatically re-indenting when opening a file, that's not quite as easy (but probably isn't a great idea since whitespace changes wreak havoc on file diffs). What might be a better course of action: you can map a shortcut for re-indention and just trigger that when you open a new file that needs fixing.

    0 讨论(0)
  • 2020-12-07 09:01

    At the bottom of the Sublime window, you'll see something representing your tab/space setting.

    You'll then get a dropdown with a bunch of options. The options you care about are:

    • Convert Indentation to Spaces
    • Convert Indentation to Tabs

    Apply your desired setting to the entire document.

    Hope this helps.

    0 讨论(0)
  • 2020-12-07 09:01

    Use the following command to get it solved :

    autopep8 -i <filename>.py
    
    0 讨论(0)
提交回复
热议问题