如何禁用vim中的内置命令
在 vim 中,当我点击 :wq
时,几乎总是在尝试输入 :w
时发生意外。我想禁用 :wq
。
我发现的最接近的是cmap,但它有一些奇怪的行为。如果我做了类似的事情,
:cmap wq w
我什至无法再输入 :wq
;它只是在命令模式下将击键序列 wq
重新映射为 w
。例如,现在我无法在包含 wq
的字符串上输入搜索/替换命令。
我只想将确切的命令 :wq
别名为 :w
或无操作。有办法做到这一点吗?
编辑:澄清为什么 :cmap
不适合我
In vim, when I hit :wq
it is almost always an accident that occurred when attempting to input :w
. I would like to disable :wq
.
The closest I found is cmap
, but it has some odd behavior. If I do something like
:cmap wq w
I can no longer even input :wq
; it just remaps the keystroke sequence wq
to w
in command mode. Now I cannot, for example, input a search/replace command on a string containing wq
.
I would just like to alias the exact command :wq
to :w
or a no-op. Is there a way to do this?
EDIT: clarified why :cmap
is not an option for me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更好的解决方案可以是:
但我不确定为什么
cmap
不能正常工作。实际上,我已经映射了一个功能键来保存文件:
更新:在第一个命令中纠正了拼写错误。
UPDATE2:可能的解决方法:
HTH
A better solution can be:
But I'm not sure why
cmap
doesn't work as excepted.Actually I had mapped one my function keys to save files:
UPDATE: typo corrected in the first command.
UPDATE2: possible workaround:
HTH
看起来最好的选择就是习惯
:cmap
行为。在极少数情况下,我想输入键盘序列wq
,我可以直接按wq
,稍等一下,然后再次按q
。我确实找到了 这个可能的解决方案,但它对我来说太复杂了口味。It looks like the best option is to just get used to
:cmap
behavior. In the rare event I want to input the keyboard seqeuncewq
I can just hitwq
, wait a second, then hitq
again. I did find this possible solution but it is too complex for my tastes.我添加了一个单行补丁并运行 dpkg-rebuildpackage 将
:wa
重命名为:wwa
:您需要在
debian/patches/< 中创建此补丁/code> 并将其添加到
debian/patches/series
。I added a one-line patch and ran dpkg-rebuildpackage for renaming
:wa
to:wwa
:You will need to create this patch in
debian/patches/
and add it todebian/patches/series
.