如何防止意外退出vim? [英] How to prevent quitting vim accidentally?

查看:44
本文介绍了如何防止意外退出vim?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将 vim 中的 :q 重新绑定到更复杂的命令以防止意外退出 vim?

Is there a way to rebind :q in vim to a more complex command to prevent accidentally exiting vim?

推荐答案

你想要的是 :close.它的作用类似于 :q 但不会让你关闭最后一个窗口:

What you want is :close. It acts like :q but won't let you close the last window:

http://vimdoc.sourceforge.net/htmldoc/windows.html#:关闭

您可以为 q 命令设置别名以映射到 close:

You can set an alias for the q command to map to close:

cabbrev q <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'close' : 'q')<CR>

感谢@Paradoxial 提供的 :cabrev 技巧.

Thanks @Paradoxial for this :cabbrev trick.

这篇关于如何防止意外退出vim?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆