我在这里找到了解决方案:http : //www.sublimetext.com/forum/viewtopic.php? f=4&t=4958
您可以修改包
trim_trailing_white_space.py
位于默认包目录中,方法是:
import sublime, sublime_plugin
def trim_trailing_white_space(view):
trailing_white_space = view.find_all("[\t ]+$")
trailing_white_space.reverse()
edit = view.begin_edit()
for r in trailing_white_space:
view.erase(edit, r)
view.end_edit(edit)
class TrimTrailingWhiteSpaceCommand(sublime_plugin.TextCommand):
def run(self, edit):
trim_trailing_white_space(self.view)
class TrimTrailingWhiteSpace(sublime_plugin.EventListener):
def on_pre_save(self, view):
if view.settings().get("trim_trailing_white_space_on_save") == True:
trim_trailing_white_space(view)
class EnsureNewlineAtEof(sublime_plugin.EventListener):
def on_pre_save(self, view):
if view.settings().get("ensure_newline_at_eof_on_save") == True:
if view.size() > 0 and view.substr(view.size() - 1) != '\n':
edit = view.begin_edit()
view.insert(edit, view.size(), "\n")
view.end_edit(edit)
现在,您可以将命令添加到键盘映射配置中:
{ "keys": ["your_shortcut"], "command": "trim_trailing_white_space" }
$ mv .git/hooks/pre-commit.sample .git/hooks/pre-commit
这是我从本博客获得的。