是否可以重新映射“wq”?保存并关闭当前缓冲区而不是在 Vim 中保存并退出?
Vim 新手。
当我发出 :wq
Ex 命令时,我想让它仅保存并关闭活动缓冲区,而不是保存它然后从 Vim 退出。
同样,我想让 :q
命令的效果与 :bd
相同。
对于如何实施这种行为有什么建议吗?
Vim newbie here.
When I issue the :wq
Ex command, I would like to make it save and close just the active buffer, instead of saving it and then quitting from Vim.
Similarly, I would like to make the :q
command to be identical to :bd
in its effect.
Any suggestions how to implement this behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Vim 允许用户在所有模式下为命令添加键映射,
包括命令行模式,因此可以定义以下内容
映射(在
.vimrc
文件中):这些命令指示 Vim 展开 WQ
在命令行中按 键进入
w|bd
并类似地展开Q 进入
bd
。有关更多详细信息,请参阅:help key-mapping
。Vim allows the user to add key mappings for commands in all modes,
including the Command-line mode, so one can define the following
mappings (in one’s
.vimrc
file):These commands instruct Vim to expand the WQ
key presses in the command line into
w|bd
and, similarly, expandQ into
bd
. See:help key-mapping
for more details.查看 Sayonara 插件。
我尝试了其他答案,但缺少用例。当我关闭最后一个缓冲区时,我希望它关闭 Vim,就像常规的
:q
命令一样。:bd
只会留下一个空白窗口,没有缓冲区。这是根据其他答案改编的映射:
Check out the Sayonara plugin.
I tried the other answer but it was missing a use case. When I close the last buffer, I want it to close Vim, like a regular
:q
command.:bd
will just leave you with a blank window and no buffer.Here's the mapping, adapted from the other answer: