Question

How would I disable autocmd's for entering/leaving windows such ":help", ":NERDTree", or ":TlistOpen"?

Right now I modify "eventignore" before and after calling those commands (besides ":help", I don't know how to do that yet), but I can't figure out a way to do that while moving around with "CTRL-w", and as a result, my autocmd's gets fired every time I enter and leave those windows.

I guess one thing that these windows have in common is that they're read-only or have restrictions on the actions I can perform. If I can get that information, I can probably put an if statement around my autocmd's.

Was it helpful?

Solution

First, set some buffer-local variables:

augroup MyAutocommands
au!
au BufNewFile,BufRead * let b:my_autocommands = DoMyAutocommands()
" other autocommands
augroup END

Create the DoMyAutocommands function. For starters,

function! DoMyAutocommands()
  if @buftype == 'help'
    return 1
  endif
  " other conditions ...
  return 0
endfun

Then each of your autocommands, or the functions they call, can check exists('b:my_autocommands') && b:my_autocommands.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top