when I use this script in my .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
It creates errors when I open the command line window via q:
(which opens up all the previous commands that I typed):
How can I fix that, and make sure that this error does not occur?
Certain commands are not allowed in the command-line-window
; :help E11
explains that.
To deal with this in your :autocmd
, there are several options:
:silent!
to the :mkview
command:try
... catch /^E11:/
to just selectively ignore this error, but report anything else:if
condition; in recent Vim versions, you can use 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