# why doesn't this autocmd take effect for neovim?

I am writing an autocmd which will warn me if the file opened is not in UTF-8 format. This is what I have got:

augroup non_utf8_file
autocmd!
autocmd BufRead * if &fileencoding != 'utf-8' | echomsg 'file not in utf-8 format!' | endif
augroup END


Unfortunately, the above autocmd does not work in Neovim when I tried to open a file which is not utf-8 encoded. No message is shown.

But if I open the same file in Vim using the above settings, the warning message is shown correctly.

## Version info:

• Neovim: 0.4.0
• Vim: 7.4
• What's the output of the command :verbose set fileencodings? when run in Neovim and Vim? – Rich May 14 at 10:53
• @jdhao Try to prefix :echom with :unsilent; i.e. unsilent echomsg 'file not in utf-8 format!' – user938271 May 14 at 11:35
• I don't know, I don't use Nvim. I tried to find more information from the issue tracker, and only found this issue. FWIW, because of the last issue, I never test whether a piece of code is processed via :echom but via a counter (let g:counter = get(g:, 'counter', 0) + 1). If g:counter exists, your piece of code was processed. The benefit of the counter is it can also tell you how many times it was processed. – user938271 May 14 at 11:45
• Thanks for pointing it out. It seems the reason. If I remove F flag from shortmess option, it seems that this issue is fixed. – jdhao May 14 at 11:53
• @Rich, I will write one. – jdhao May 15 at 2:33

This issue is caused by the F flag in the shortmess option[1]. If you remove the F flag from shortmess, you can see the displayed message correctly. This issue has been filled as #8675 and #9870.
As an alternative, if you change the autocmd event from BufRead to BufEnter or BufWinEnter, the message can be shown without removing the F flag.
[1] Thanks to user938271 for pointing out that the F flag is added in this neovim commit.