我知道Sublime Text 2可以在保存时删除文件上的尾随空格。
在团队中工作并对文件进行更改时,这往往会产生巨大的差异,使同行代码审查变得更加繁琐。出于这个原因,我倾向于仅在我对文件进行大量更改时才进行空白区域清理,并留下空白区域以进行微小更改。
我想知道是否有任何命令在"Activate trimming on save > Save file > Deactivate trimming"
以外的文件上按需执行白色空间的修剪。
在文档和stackoverflow中搜索没有显示任何相关内容,所有链接似乎都在讨论保存时的自动修剪。
我使用TrailingSpaces插件。
突出显示尾随空格并在闪存中删除它们。
ST2提供了一种在文件保存时自动删除尾随空格的方法。根据您的设置,只需突出显示和/或手动删除它们可能会更方便。这个插件提供了这一点!
用法:单击“编辑/尾随空格/删除”。
要添加键绑定,请打开“首选项/键绑定 - 用户”并添加:
{ "keys": ["ctrl+alt+t"], "command": "delete_trailing_spaces" }
我使用这些步骤在Sublime Text中快速按需解决方案:
[ \t]+\n
\n
您也可以通过以下方式为大量文件执行此操作
[ \t]+\n
\n
这是一种超级简单的方法,它不使用任何插件或设置,并且在大多数情况下都可以使用。
如何多选所有行:
一种方法是使用鼠标中键垂直选择,然后点击结束键,如果它是一个小选择。
使用热键:
您还可以使用find函数查找每行中的内容,例如空格字符:
示范文本:
text and number 44 more text and a space
text and number 44 more text and 2 tabs
text and number 44 more text and no space or tab
text and number 44 more text after a line feed
我在这里找到了一个解决方案:qazxsw poi
您可以修改包
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)