How do I prevent my vim autocmd from running in the command-line window?

Tag: vim Author: meidiwusi Date: 2012-07-14

I use an autocommand to close the preview window when I leave insert mode as described in this answer. But when I am in the command-line window (q:), I get an error: E11: Invalid in the command-line window; <CR> executes, CTRL-C quits: :pclose|endif

How can I prevent this error?

I tried running :set in the command-line window and a regular window, but no obvious option revealed itself in the diff.

Best Answer

Use silent! to suppress the error:

autocmd CursorMovedI *  if pumvisible() == 0|silent! pclose|endif
autocmd InsertLeave * if pumvisible() == 0|silent! pclose|endif

comments:

Of course! Thanks.