强制 GVim 在关闭前提示 [英] Force GVim to prompt before close
问题描述
我最近一直在过渡到 GVim,因为我发现它在终端中比 vim 更美观,而且速度更快.我有这个非常不好的习惯,我正试图改掉.当我从命令行使用 vim 时,我的工作流程是这样的:
I've been making a transition to GVim lately, because I find it to be more aesthetically pleasing and a little bit faster then vim in the terminal. I have this really bad habit that I'm trying to break. When I used vim from the command line my work flow was like this:
vim filename.txt
# make some edits
ZZ
# do other stuff
vim otherfile.txt
# make some edits
ZZ
现在使用 GVim,我最终关闭编辑器过于频繁.我想知道是否有办法强制 GVim 在我执行 :wq
或 ZZ
时提示我或打开一个空缓冲区.有什么想法吗?
Now using GVim, I end up closing the editor far too frequently. I'm wondering if there is a way to force just GVim to either prompt me or open an empty buffer when I do a :wq
or ZZ
. Any ideas?
我知道如何重新映射键,但我想知道是否有办法强制 GVim 在从命令行调用 vim 时具有不同的行为.
I know how to remap keys, but I'm wondering if there is a way to force GVim to have a different behavior then when vim is called from the command line.
推荐答案
在ZZ
上调用一个函数,如果只剩下一个tab和一个窗口,提示是否关闭(默认为关闭).参见:help confirm()
.
Call a function on ZZ
and if there is only one tab and window left, prompt whether to close or not (default is to close). See :help confirm()
.
nnoremap ZZ :call QuitPrompt()<cr>
fun! QuitPrompt()
if has("gui_running") && tabpagenr("$") == 1 && winnr("$") == 1
let choice = confirm("Close?", "&yes\n&no", 1)
if choice == 1 | wq | endif
else | wq | endif
endfun
这篇关于强制 GVim 在关闭前提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!