我知道有很多关于这个问题的帖子,但我无法让它工作。<br>。 我在编码时使用制表符。有什么方法可以将空格转换成制表符吗?例如,在打开和保存文件时?有没有人有办法?
//编辑:
我想做的是自动!-> 打开、保存或在飞行中<bR>。
有没有人知道如何做?
我试过这个。
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
}
你可能已经知道,你可以在Preferences.sublim-settings
中定制你的缩进设置,例如。
"detect_indentation": true,
"tab_size": 4,
"translate_tabs_to_spaces": false
这将把你的编辑器设置为使用4个空格宽的制表符,并将覆盖默认行为,使Sublime与你正在编辑的任何文件的缩进一致。有了这些设置,重新缩进文件将导致任何空格被替换为制表符。
至于在打开文件时自动重新缩进,那就不太容易了(但可能也不是个好主意,因为空白的变化会对文件的差异造成破坏)。更好的做法是:你可以映射一个重新缩进的快捷方式,当你打开一个需要修正的新文件时,就触发这个快捷方式。