Following code switches off Vim syntax highlighting for buffers opened after its execution.
autocmd BufAdd * exe 'buffer ' . expand('<abuf>')
Why? Is it bug?
In the comment you describe, that you want to do
nmap <buffer> on
BufAdd is very early in the processing, the use-cases for this
event are limited.
If you want to do buffer local mappings, you should do that with
autocmd BufEnter or with
autocmd BufEnter *.c nnoremap <buffer> ... autocmd FileType c nnoremap <buffer> ...
BTW: You should prefer
map. See the answer to this question.
Back to your initial question:
Autocmds are blocked while another autocmd is running. In your case, you use an
BufAdd to immediately switch to the new buffer. Switching to a new
buffer needs to read the file and would normally trigger the
BufEnter autocmds, that are used to determine the file type and hence the
As this switch to the buffer is done in the context of an autocmd, the
BufRead events are not triggered. So no file type detection and hence
no syntax highlighting.
Don't use the following in your case, use another autocmd event as described above.
It is possible, to allow nested autocmds by adding the keyword
autocmd BufAdd * nested ....
Then autocmds are triggered while the this autocmd is running.
You might want to read
:help autocmd-nested for the details.