Archive for December 8th, 2004
磨刀不误砍柴功 (1)EditPlus
by tonny.xu on Dec.08, 2004, under General
俗话说:公欲善其事,必先利其器。
KEYWORDS: 公欲善其事,必先利其器, EditPlus, 正则表达式, Regular Expression, Grep.
作为一个开发人员必须首先学会使用工具,今天就是磨刀不误砍柴功的第一天,介绍强劲的文本编辑器: EditPlus。
EditPlus 是一个非常小巧,但是非常强劲的文本编辑器;1.1M的大小,绝对不会占用硬盘空间,但是绝对是一个经常会用到的文本编辑器,同时EditPlus还是一个绿色的软件,copy了以后到哪里都可以用。
EditPlus主页这个软件是一个韩国人写的??,在我写这篇文章之前我都没有注意这一点??

这里重点介绍几个小技巧:
1、Find in Files….
以前在候捷老师的一片关于如何阅读源代码的文章中(见《程序员》2002年04期),候捷老师提到了他喜欢用grep,并且特意提到了这个grep是出自于Borland的C++ Builder中的一个附带工具,不过后来找了一下,不容易找到,候捷老师提供的下载站点也已经关闭多时了。这个grep最大的作用莫过于可以在任意多个不确定的文本文件中寻找你需要的某个字符串。想当年我到处去找这个grep,后来在一个不经意的时候发现,EditPlus的这个功能已经做的非常完善了。
完全不需要用那个DOS模式下的程序,快速并且方便的在n个文件中找到你要的string,并且可以任意的处理这个string。我经常需要在数百个HTML文件中替换一个IMG的src,配合正则表达式,一眨眼的功夫就可以处理完毕。(这里有一个不能说坏也不能说好的处理,作者完全可以支持在不打开文件的情况替换,但是作者可能是考虑到替换的风险,宁可让用户自己去承担这个风险,结果我的风险就是在EditPlus同时打开超过200个以上的文本文件的时候导致的EditPlus不响应)
(虽然现在大部分的文本编辑软件都已经提供了这个功能,但是EditPlus就是胜在他的小巧和简单上)
2、虽然不是无所不能,但是绝对是够用的正则表达式
EditPlus的正则表达式简化了我们在Perl或者Java或者在Javascript中使用的那些个完善的正则表达式,他的内容只有简单的几条:
| EditPlus supports following regular expressions in Find, Replace and Find in Files command. | |
| Expression | Description |
| t | Tab character. |
| n | New line. |
| . | Matches any character. |
| | | Either expression on its left and right side matches the target string. For example, "a|b" matches "a" and "b". |
| [] | Any of the enclosed characters may match the target character. For example, "[ab]" matches "a" and "b". "[0-9]" matches any digit. |
| [^] | None of the enclosed characters may match the target character. For example, "[^ab]" matches all character EXCEPT "a" and "b". "[^0-9]" matches any non-digit character. |
| * | Character to the left of asterisk in the expression should match 0 or more times. For example "be*" matches "b", "be" and "bee". |
| + | Character to the left of plus sign in the expression should match 1 or more times. For example "be+" matches "be" and "bee" but not "b". |
| ? | Character to the left of question mark in the expression should match 0 or 1 time. For example "be?" matches "b" and "be" but not "bee". |
| ^ | Expression to the right of ^ matches only when it is at the beginning of line. For example "^A" matches an "A" that is only at the beginning of line. |
| $ | Expression to the left of $ matches only when it is at the end of line. For example "e$" matches an "e" that is only at the end of line. |
| () | Affects evaluation order of expression and also used for tagged expression. |
| Escape character. If you want to use character "" itself, you should use "". | |
|
The tagged expression is enclosed by (). Tagged expressions can be referenced by , 1, 2, 3, etc. indicates a tagged expression representing the entire substring that was matched. 1 indicates the first tagged expression, 2 is the second, etc. See following examples. |
|
我相信EditPlus的作者绝对不是实现不出一套完整的正则表达式,只是他决定这样的正则表达式已经足以应付文字检索替换这些操作了。UltraEdit是另外一款非常不错的文本编辑器,但是最终我舍弃了UE而选择了EP,就是因为EP的简单明了。UE中实现了一个非常完整的正则表达式,但是实际上在使用文本查找和替换这些工作的时候根本用不上其中的许多功能。
(或许许多人,对上面的正则表达式不理解,那不是本文要讨论的东西)
3、为Internet的开发作了充分的优化
对于那些HTML和Javascript的编辑者,EditPlus是不二的选择,尤其是经常写Javascript的人,一个Ctrl+B就可以让你里面看到你的Javascript脚本执行结果,真爽。EditPlus本身HTML标准和许多的程序语法做了语法文件,HTML, CSS, PHP, ASP, Perl, C/C++, Java, JavaScript and VBScript等等。
个人尤其推荐经常使用HTML,CSS,PHP,Java,Javascript的用户使用EditPlus。
小巧、轻便、功能强劲、界面简洁、功能实用??,这样充分的理由还有其他什么选择么?