我想知道 vim 专家如何在 vim 中使用宏进行日常编码 - 我有很多经常使用的自定义快捷方式/映射,但没有遇到任何关于宏的好主意。
它可能是您以前使用过的一个宏,用于极大地简化任务 - 我只需要有关如何在 vim 中有效地使用此功能的想法!
最佳答案
宏通常是一种“动态”自动化工具。假设您有一个项目列表:
apple orange banana grapes cantaloupe
You can quickly write a macro to make them into an html list for example. Starting from the beginning of the word apple record the following macro: i<li><Esc>A</li><Esc><CR>
into register 1.
The <CR> is key because it allows you to jump to the next line and thus use the "count" modifier on your macro execution which provides multiline macro execution
Then go to the beginning of orange and use 4@1 ([count]@[register letter]) to apply the macro to the rest of the entries to get this:
<li>apple</li>
<li>orange</li>
<li>banana</li>
<li>grapes</li>
<li>cantaloupe</li>
想象一下在 200 个项目的列表中使用它。节省时间不是吗?
当然,这个例子是微不足道的,你可以通过搜索和替换来做到这一点,但你可以想象更复杂的例子......
关于vim - 您在 Vim 中使用过的最喜欢/最高效的宏是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1891941/