Sublime Text 3, convert spaces to tabs

前端 未结 11 2398
[愿得一人]
[愿得一人] 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:47

    You can do replace tabs with spaces in all project files by:

    1. Doing a Replace all Ctrl+Shif+F
    2. Set regex search ^\A(.*)$
    3. Set directory to Your dir
    4. Replace by \1

    5. This will cause all project files to be opened, with their buffer marked as dirty. With this, you can now optionally enable these next Sublime Text settings, to trim all files trailing white space and ensure a new line at the end of every file.

      You can enabled these settings by going on the menu Preferences -> Settings and adding these contents to your settings file:

      1. "ensure_newline_at_eof_on_save": true,
      2. "trim_trailing_white_space_on_save": true,
    6. Open the Sublime Text console, by going on the menu View -> Show Console (Ctrl+`) and run the command: import threading; threading.Thread( args=(set(),), target=lambda counterset: [ (view.run_command( "expand_tabs", {"set_translate_tabs": True} ), print( "Processing {:>5} view of {:>5}, view id {} {}".format( len( counterset ) + 1, len( window.views() ), view.id(), ( "Finished converting!" if len( counterset ) > len( window.views() ) - 2 else "" ) ) ), counterset.add( len( counterset ) ) ) for view in window.views() ] ).start()
    7. Now, save all changed files by going to the menu File -> Save All

提交回复
热议问题