是否可以重新映射“wq”?保存并关闭当前缓冲区而不是在 Vim 中保存并退出?

发布于 2024-09-30 19:07:32 字数 167 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌生 2024-10-07 19:07:32

Vim 允许用户在所有模式下为命令添加键映射,
包括命令行模式,因此可以定义以下内容
映射(在 .vimrc 文件中):

:cnoreabbrev wq w<bar>bd
:cnoreabbrev q bd

这些命令指示 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):

:cnoreabbrev wq w<bar>bd
:cnoreabbrev q bd

These commands instruct Vim to expand the WQ
key presses in the command line into w|bd and, similarly, expand
Q into bd. See :help key-mapping for more details.

以可爱出名 2024-10-07 19:07:32

查看 Sayonara 插件

我尝试了其他答案,但缺少用例。当我关闭最后一个缓冲区时,我希望它关闭 Vim,就像常规的 :q 命令一样。 :bd 只会留下一个空白窗口,没有缓冲区。

这是根据其他答案改编的映射:

" Prevent accidental closing of all buffers when doing :wq or :q
cnoreabbrev wq w<bar>Sayonara
cnoreabbrev  q       Sayonara

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:

" Prevent accidental closing of all buffers when doing :wq or :q
cnoreabbrev wq w<bar>Sayonara
cnoreabbrev  q       Sayonara
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文