pas
pas

Reputation: 13

Exclude help and plugin pages from autocmd pattern

I want to write command like autocmd BufAdd * if &filetype != 'help' | echo 'foo', but it didn't work. I've tried different options: &l:filetype, &buftype, &l:buftype; tried with toggled filetype setting, but nothing changed. Global command autocmd BufAdd * echo 'bar' worked everywhere includes help pages, and the same time :echo &filetype on help pages returns help. What am I doing wrong?

Upvotes: 0

Views: 354

Answers (1)

Matt
Matt

Reputation: 15186

Because,

  1. While in BufAdd the current buffer can be (and quite probably is) different from the matched buffer;
  2. While in BufAdd the matched buffer may (and quite probably will) not have any &filetype set yet.

Note that normally one should hook into some specific FileType with ~/.vim/after/ftplugin/xyz.vim instead.

Upvotes: 1

Related Questions