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?
Asked
Active
Viewed 279 times
0

pas
- 13
- 1
- 3
-
2"What am I doing wrong?" You are not telling us what problem you are trying to solve. – romainl May 08 '21 at 11:12
-
@romainl, my fault. I'm trying to write command which will perform some function when I create new buffer, only if this buffer is not help or plugin page. But test command with the "if &filetype != 'help'" has the same behavior as command without this part (both triggers on help pages), which is what I was trying to describe. – pas May 08 '21 at 13:00
1 Answers
1
Because,
- While in
BufAdd
the current buffer can be (and quite probably is) different from the matched buffer; - 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.

Matt
- 13,674
- 1
- 18
- 27
-
Thank you, that was the problem. I wrapped condition in timer_start for test, and got the behavior that I expected. – pas May 08 '21 at 13:16