相反,我希望它关闭文件并打开默认 No Name
缓冲。有时我不小心关闭了最后一个文件,我必须重新启动 gvim 和 cd 到正确的目录。
最佳答案
把它放在你的 $MYVIMRC
function! NumberOfWindows()
let i = 1
while winbufnr(i) != -1
let i = i+1
endwhile
return i - 1
endfunction
function! DonotQuitLastWindow()
if NumberOfWindows() != 1
let v:errmsg = ""
silent! quit
if v:errmsg != ""
"echohl ErrorMsg | echomsg v:errmsg | echohl NONE
"echoerr v:errmsg
echohl ErrorMsg | echo v:errmsg | echohl NONE
endif
else
echohl Error | echo "Can't quit the last window..." | echohl None
endif
endfunction
if has("gui_running")
cnoreabbrev <expr> q getcmdtype() == ":" && getcmdline() == 'q' ? 'call DonotQuitLastWindow()' : 'q'
cnoreabbrev <expr> qa getcmdtype() == ":" && getcmdline() == 'qa' ? 'call DonotQuitLastWindow()' : 'qa'
endif
关于vim - 当我输入 `:q` 或 `:qa` 时,如何使 gvim 主窗口不退出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9530734/