2

From :h autocmd-nested, it says "By default, autocommands do not nest." But nested FileType events are triggered anyway without using ++nested. As seen in this test:

autocmd BufNewFile,BufRead tst setlocal filetype=tst | let b:tst = 1
autocmd FileType tst let b:tst = 2 | let b:filetype_event_triggered = 'true'

Running e tst | echo b:tst prints 1, showing that the FileType autocommand is run before let b:tst = 1.

So is FileType event supposed to always run nested despite what the manual says, or am I missing something?

(Using vim 8.1)

1
2

Yes, setting some options in Vim may have various side effects (see source code). In particular, setting &filetype and &syntax triggers the corresponding autocommands, even if invoked from inside another autocommand and no nested attribute is provided.

I'm not sure if it's documented anywhere, but standard Vim scripts, such as filetype.vim etc., heavily rely on this and never ever say "nested" either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.