我该如何防止vim autocmd在命令行窗口中运行?

4
我使用自动命令来关闭预览窗口,当我退出插入模式时,正如这个答案所描述的那样。但是当我在命令行窗口 (q:) 中时,我会收到一个错误:E11: Invalid in the command-line window; <CR> executes, CTRL-C quits: :pclose|endif
我该如何避免这个错误?
我尝试在命令行窗口和常规窗口中运行:set,但没有明显的选项在差异中显示出来。
1个回答

6

使用 silent! 命令可以抑制错误:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接