问题描述
有谁知道如何正确保存/重用 vim 编辑器中记录的宏?
Does anyone know how to properly save/reuse macros recorded inside of a vim editor?
推荐答案
使用 q
后跟一个字母来记录宏.这只是进入复制/粘贴寄存器之一,因此您可以在正常模式下使用 "xp
或 "xP
命令正常粘贴它,其中 x 是注册粘贴.
Use q
followed by a letter to record a macro. This just goes into one of the copy/paste registers so you can paste it as normal with the "xp
or "xP
commands in normal mode, where x is the register to paste.
为了保存它,你打开.vimrc并粘贴内容,然后下次启动vim时寄存器就会出现.
格式类似于:
To save it you open up .vimrc and paste the contents, then the register will be around the next time you start vim.
The format is something like:
let @q = 'macro contents'
不过要小心引号.他们必须正确逃脱.
Be careful of quotes, though. They would have to be escaped properly.
所以要保存宏,您可以这样做:
So to save a macro you can do:
- 普通模式:
qq
- 输入任何命令
- 从普通模式:
q
- 打开.vimrc
"qp
将宏插入到您的let @q = '...'
行
- From normal mode:
qq
- enter whatever commands
- From normal mode:
q
- open .vimrc
"qp
to insert the macro into yourlet @q = '...'
line
这篇关于保存 vim 宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!