VIM ..根据正则表达式划分多行

时间:2010-12-26 16:58:56

标签: vim

这是我的情况我有很多SQL行,如下所示。

SET IDENTITY_INSERT blah
DELETE FROM blah
SET IDENTITY_INSERT blah
DELETE FROM blah
SET IDENTITY_INSERT blah
DELETE FROM blah
SET IDENTITY_INSERT blah
DELETE FROM blah
SET IDENTITY_INSERT blah
DELETE FROM blah

我想用VIM重新排列它

SET IDENTITY_INSERT blah
SET IDENTITY_INSERT blah
SET IDENTITY_INSERT blah
SET IDENTITY_INSERT blah
DELETE FROM blah
DELETE FROM blah
DELETE FROM blah

现在我知道我可以写一个简单的python脚本来快速实现这个目标,但我正在努力提高我的VIM技能。

2 个答案:

答案 0 :(得分:7)

您可以使用g命令:

:g/^DELETE/m$

这会将(m)以DELETE开头的所有行移动到文件末尾($)。

答案 1 :(得分:1)

以下内容不使用任何正则表达式...

:sort!

详细信息:http://vim.wikia.com/wiki/Sort_lines