相反,我希望它关闭文件并打开默认的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