Vim 如何为autocmd设置与命令行缓冲区不匹配的文件模式?
我使用au命令检查文件是否已更改:Vim 如何为autocmd设置与命令行缓冲区不匹配的文件模式?,vim,autocmd,Vim,Autocmd,我使用au命令检查文件是否已更改: autocmd CursorHold * checktime 但是当我使用q:或q/启动命令行窗口时,我会得到以下错误: Error detected while processing CursorHold Auto commands for "*": E11: Invalid in command-line window; <CR> executes, CTRL-C quits: checktime Press ENTER or type co
autocmd CursorHold * checktime
但是当我使用q:或q/启动命令行窗口时,我会得到以下错误:
Error detected while processing CursorHold Auto commands for "*":
E11: Invalid in command-line window; <CR> executes, CTRL-C quits: checktime
Press ENTER or type command to continue
我的问题是,是否可以设置autocmd的模式以排除命令行缓冲区和其他只读缓冲区?最简单的修复方法是只消除错误:
autocmd CursorHold * silent! checktime
或者,您也可以将其包装在try…catch/:E11:/中。或者,您可以尝试检查命令行窗口:
autocmd CursorHold * if expand('%') !=# '[Command Line]' | checktime | endif
最简单的修复方法是消除错误:
autocmd CursorHold * silent! checktime
或者,您也可以将其包装在try…catch/:E11:/中。或者,您可以尝试检查命令行窗口:
autocmd CursorHold * if expand('%') !=# '[Command Line]' | checktime | endif
您还可以检查以确保“buftype”为空。以下是一个目标不同但需求相似的答案:您还可以检查以确保“buftype”为空。以下是目标不同但需求相似的答案: