How to disable a built-in command in vim

核能气质少年 提交于 2019-12-10 03:56:10

问题


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


回答1:


A better solution can be:

:cabbrev wq w

But I'm not sure why cmap doesn't work as excepted. Actually I had mapped one my function keys to save files:

:map <F2> :w<CR>
:nmap <F2> <ESC>:w<CR>i

UPDATE: typo corrected in the first command.

UPDATE2: possible workaround:

:cabbrev wq<CR> w

HTH




回答2:


It looks like the best option is to just get used to :cmap behavior. In the rare event I want to input the keyboard seqeunce wq I can just hit wq, wait a second, then hit q again. I did find this possible solution but it is too complex for my tastes.



来源:https://stackoverflow.com/questions/1787127/how-to-disable-a-built-in-command-in-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!