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

前端之家收集整理的这篇文章主要介绍了如何在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命令之后,获得交替的命令和打印行.

原文链接:https://www.f2er.com/bash/384627.html

猜你在找的Bash相关文章