有时我需要在文件中插入一些相似的行,这些行仅在序列号上有所不同。例如,
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 以继续生成新的
print
带有递增数字的行。对于您的第二个示例,您只需添加
j : Moves one line down
后
yy
命令,以获得交替的命令行和 print
的。
关于vim - 在 vim 中插入类似行时,如何最大限度地减少击键次数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3984967/