Jos*_*uis 95 whitespace code-cleanup sublimetext2
我知道Sublime Text 2可以在保存时删除文件上的尾随空格.
在团队中工作并对文件进行更改时,这往往会产生巨大的差异,使同行代码审查变得更加繁琐.出于这个原因,我倾向于仅在我对文件进行大量更改时才进行空白区域清理,并留下空白区域以进行微小更改.
我想知道是否有任何命令在文件上按需执行修剪空白区域"Activate trimming on save > Save file > Deactivate trimming".
在文档和stackoverflow中搜索没有显示任何相关内容,所有链接似乎都在讨论保存时的自动修剪.
Sri*_*kam 70
我使用TrailingSpaces插件.
突出显示尾随空格并在闪存中删除它们.
ST2提供了一种在文件保存时自动删除尾随空格的方法.根据您的设置,只需突出显示和/或手动删除它们可能会更方便.这个插件提供了这一点!
用法:单击"编辑/尾随空格/删除".
要添加键绑定,请打开"首选项/键绑定 - 用户"并添加:
{ "keys": ["ctrl+alt+t"], "command": "delete_trailing_spaces" }
Run Code Online (Sandbox Code Playgroud)
小智 63
我使用这些步骤在Sublime Text中快速按需解决方案:
[ \t]+\n\n您也可以通过以下方式为大量文件执行此操作
[ \t]+\n\nant*_*tou 23
您只需使用正则表达式删除尾随空格:
[^\S\r\n]+$[^\S\r\n]+$ 是正则表达式"至少有一个空白字符(所以空格和制表符,但不是新行,使用双重否定),后面是行的结尾"
sha*_*rey 20
这是一种超级简单的方法,它不使用任何插件或设置,并且在大多数情况下都可以使用.
现在应该选择行尾的空格和制表符.按删除或退格键
注意 - 特殊字符如(和+)也可以在此行的末尾选择,而不仅仅是空格.
如何多选所有行:
一种方法是使用鼠标中键垂直选择,然后点击结束键,如果它是一个小选择.
使用热键:
您还可以使用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
Run Code Online (Sandbox Code Playgroud)
Ric*_*tti 13
我在这里找到了一个解决方案:http://www.sublimetext.com/forum/viewtopic.php? f = 4&t = 4958
您可以修改包
trim_trailing_white_space.py
Run Code Online (Sandbox Code Playgroud)
位于默认包目录中,这样:
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)
Run Code Online (Sandbox Code Playgroud)
现在,您可以将命令添加到键盘映射配置中:
{ "keys": ["your_shortcut"], "command": "trim_trailing_white_space" }
Run Code Online (Sandbox Code Playgroud)