问题描述
我正在尝试向 Textmate 添加一个宏/命令以进行一些文件清理,而我还没有弄清楚的最后一点是简单地从文件的开头和结尾删除空行 -- 有谁知道如何做这个?我知道一定存在一些 Textmate 或正则表达式技巧,只是不确定是什么......
I'm trying to add a macro/command to Textmate for some file cleanup and the last tidbit I haven't figured out is simply to remove blank lines from the beginning and end of a file -- does anyone know how to do this? I know some Textmate or regex trick must exist, just not sure what...
推荐答案
对于您提到的任务,您可以使用文本"包中的内置命令.
For the tasks you mentioned, you can use built-in commands from the "Text" Bundle.
即使您只想编写自己的脚本,我也建议您将这些用作模板以供您自己努力.
Even if you just want to script your own, i would suggest using these as templates for your own efforts.
要访问这些:
删除尾随空格:
ctrl-cmd-t 调出上下文相关的捆绑菜单
ctrl-cmd-t to bring up the context-sensitive Bundle menu
开始输入remove trailing",在你完成删除"之前,你应该看到删除尾随Spaces"命令移动到顶部菜单(此命令在文本"捆绑包,捆绑包之一包含在 TextMate 中)
begin typing "remove trailing",before you finish "remove", youshould see the "Remove TrailingSpaces" Command move to the top ofthe menu (this Command is in the"Text" Bundle, one of the Bundlesincluded with the TextMate )
回车"将执行命令(假设光标位于正确等)
"enter" will execute the command(assume the cursor is positionedcorrectly, etc.)
或者,您可以使用等效键访问此命令,但由于默认 TextMate 安装中未分配,因此您需要自己分配它,这很简单:
Alternatively, you can access this Command using a key equivalent, but since one is not assigned in the default TextMate installation, you'll need to assign it yourself, which is simple to do:
ctrl-alt-cmd-b 调出捆绑编辑器
找到 Text Bundle 然后点击删除尾随空格"命令
find the Text Bundle then click onthe "Remove Trailing Spaces" Command
在右上角编辑器,切换设置"并输入等效键或选项卡"触发器"(由输入一些组合键你分配后跟 Tab 键.
In the upper right-hand-side of theEditor, toggle "Settings" and entereither a key equivalent or a "tabtrigger" (which is activated byentering some key combination youassigned followed by the tab key.
删除前导空格:
这是一个宏而不是命令.通过预先配置的等效键(cmd-del
This one's a macro rather than a command. It's probably easiest to access it via it's pre-configured key-equivalent, which is cmd-del
这篇关于Textmate/Regex:从文件的开头/结尾去除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!