Vim - 命令行加载视图和 mkview 错误 window

Vim - load view and mkview errors in command line window

当我在我的 .vimrc 中使用这个脚本时:

"Save and restore folds when a file is closed and re-opened
autocmd BufWinEnter                    ?* if(!empty(glob(expand("%:p")))) | silent loadview | endif
autocmd BufWritePost,BufLeave,WinLeave ?* if(!empty(glob(expand("%:p")))) | mkview          | endif

当我通过 q: 打开命令行 window 时会产生错误(这会打开我之前输入的所有命令):

我该如何解决这个问题,并确保不会发生此错误?

某些命令在 command-line-window; :help E11 解释中是不允许的。

要在您的 :autocmd 中处理此问题,有几种选择:

  • 通过在 :mkview 命令前添加 :silent! 来抑制任何错误
  • 在调用周围加上 :try ... catch /^E11:/ 以选择性地忽略此错误,但报告其他任何内容
  • 在您的 :if 条件中添加对命令行 window 的检查;在最近的 Vim 版本中,您可以使用 getcmdwintype(); it returns an empty String in other windows; for a check that also works with older Vim versions, see ingo#compat#window#IsCmdlineWindow() in my ingo-library plugin