微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在vim中插入类似的行时最小化击键?

有时我需要在文件中插入一些类似的行,这些行仅在序列号上有所不同.例如,
print "func 1";
print "func 2";
print "func 3";
print "func 4";
print "func 5";

使用vim,我最后使用[yypppp]复制粘贴第一行,然后更改最后四行.如果要插入更多行,这非常慢.

在vim中有更快的方法吗?

一个例子是:

Initial state

boot();
format();
parse();
compare();
results();
clean();

Final state

print "func 1";
format();
print "func 2";
parse();
print "func 3";
compare();
print "func 4";
results();
print "func 5";
clean();
录制一个宏.以下是您的特定示例的工作流程:

复制粘贴第一行.然后,

qa       : Start recording macro to register a
yy       : Yank current line
p        : Paste current line in line below
/\d      : Search for start of number (you can skip this command,the next command automagically moves the cursor to the number)
C-A      : Control-A increments the number
q        : Stop recording macro
3@a      : Replay macro 3 times

您可以使用任意数字替换3以继续生成具有递增数字的新打印行.

对于您的第二个示例,您可以添加

j        : Moves one line down

在yy命令之后,获得交替的命令和打印行.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐