如何防止我的 vim autocmd 在命令行窗口中运行? [英] How do I prevent my vim autocmd from running in the command-line window?

查看:23
本文介绍了如何防止我的 vim autocmd 在命令行窗口中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在离开插入模式时使用自动命令关闭预览窗口,如此答案中所述.但是当我在命令行窗口 (q:) 中时,出现错误:E11: Invalid in the command-line window;<CR>执行,CTRL-C 退出: :pclose|endif

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

如何防止出现此错误?

我尝试在命令行窗口和常规窗口中运行 :set,但在差异中没有显示出明显的选项.

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

推荐答案

使用 silent! 来抑制错误:

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

这篇关于如何防止我的 vim autocmd 在命令行窗口中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆