1

I have an au command to check if a file had been changed:

autocmd CursorHold * checktime

But when I launch a command line window with q: or with q/ than I get the following error:

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

My question is, is it possible to set up the autocmd's pattern to exclude command line buffers and other readonly buffers?

Gabor Marton
  • 2,039
  • 2
  • 22
  • 33

1 Answers1

4

The easiest fix is to just silence the errors:

autocmd CursorHold * silent! checktime

Alternatively, you could also wrap this in try...catch /:E11:/. Or, you could attempt to check for the command-line window:

autocmd CursorHold * if expand('%') !=# '[Command Line]' | checktime | endif
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • You can also check to make sure `'buftype'` is empty. Here is the answer with a different goal but similar needs: [Vim: Creating parent directories on save](http://stackoverflow.com/a/4294176/438329) – Peter Rincker Aug 18 '14 at 13:17