vimviautocmdneovim

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?


Solution

  • 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.