vim - 您在 Vim 中使用过的最喜欢/最高效的宏是什么?

标签 vim macros keyboard-shortcuts

我想知道 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/

相关文章:

python - jedi-vim 与 jedi 输出不一致

c - 表达式中大括号组的 ISO C 等价物

Javascript动态调用shortcutjs插件的快捷键组合功能

vim - 如何禁用 vim 中的所有键映射?

vim - shellescape 函数中的数字 1 在 vi​​m 中是什么意思?

git - 如何在 Git Bash 中找到 Vim 的绝对路径?

c++ - 过度依赖宏

c++ - C++ 中的 asm block 作为宏

ios - 如何禁用 Mac Catalyst 应用程序中的默认键盘导航?

vim - 如何*直接*增加光标下的数字?