相反,我希望它关闭文件并打开默认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
Run Code Online (Sandbox Code Playgroud)