我知道有很多关于这个的帖子,但我不能让它工作。
我使用标签来编码。有没有办法,把空格转换成制表符?即打开和保存文件?有人知道吗?
/ /编辑:
我的愿望是自动做到这一点!->打开,保存或在飞行
有人知道怎么做吗?
我试了一下:
import sublime, sublime_plugin, os
class ExpandTabsOnSave(sublime_plugin.EventListener):
# Run ST's 'expand_tabs' command when saving a file
def on_pre_save(self, view):
if view.settings().get('expand_tabs_on_save') == 1:
view.window().run_command('expand_tabs')
下面是我的用户设置:
{
"auto_complete_selector": "source - comment, meta.tag - punctuation.definition.tag.begin",
"auto_indent": true,
"detect_indentation": true,
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"expand_tabs_on_save": true,
"font_face": "SourceCodePro-Regular",
"font_size": 10,
"format_on_save": true,
"ignored_packages":
[
"Vintage"
],
"indent_to_bracket": true,
"open_files_in_new_window": false,
"smart_indent": true,
"tab_size": 4,
"translate_tabs_to_spaces": false,
"trim_automatic_white_space": true,
"trim_trailing_white_space_on_save": true,
"use_tab_stops": false,
"word_wrap": false
}
你可以用空格替换所有项目文件中的制表符:
Doing a Replace all Ctrl+Shif+F
Set regex search ^\A(.*)$
Set directory to Your dir
Replace by \1
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:
"ensure_newline_at_eof_on_save": true,
"trim_trailing_white_space_on_save": true,
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()
Now, save all changed files by going to the menu File -> Save All
你可以用空格替换所有项目文件中的制表符:
Doing a Replace all Ctrl+Shif+F
Set regex search ^\A(.*)$
Set directory to Your dir
Replace by \1
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:
"ensure_newline_at_eof_on_save": true,
"trim_trailing_white_space_on_save": true,
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()
Now, save all changed files by going to the menu File -> Save All