0

My init.vim is just

au FileType * echom "test"

However, if I open a file, neovim-qt will not echo test. If I load a new file while the window is open, it will also not work.

I have managed to find one case where it will fire. If I run mks, open Session.vim and then source it (so%), it will run this for every file that gets opened from that.

Any idea what's going on?

Edit: running set filetype... will cause it to trigger.

2

It took a winding road to reach the root cause. Jump to the last/second update below to skip to the conclusion.

Per :h FileType the FileType event doesn't do anything unless 'filetype' is set. The standard way to set that is to have this in your vimrc/init.vim:

:filetype on

This "enables file type detection".

You don't have anything in your init.vim so that's surely why this stuff isn't working "out of the box". Your Session.vim file, which contains a bunch of config, likely was created when filtype was enabled. That's why things work after you source it.

BTW, you should be doing autocommands like this:

augroup myautocmds
  autocmd!
  au FileType * echom "test"
augroup END

This allows you to safely re-source the file containing your autocommand(s).

UPDATE: Okay, current state of affairs is that everything is working with above, generally speaking, but echom doesn't not produce any visible output. I use echom in autocommands in vim but I'm wondering if filetype event specifically poses a problem. Other actions, e.g. setting a variable, work fine. Investigating further...

UPDATE 2: After it's all said and done it looks like it boils down to this: echom with FileType autocommands is not reliable. Works with other event types. Works with vim. Not with neovim and file type. If OP happened to use a different command (e.g. set a variable and checked the value) they might not have ended up here at all.

(Opening a bug with Neovim might be prudent.)

UPDATE 3: Just to formalize the conclusions I automated some tests so I could be sure that there is a discrepancy between neovim's behavior and vim's...as opposed to some human error leaking in. Tests were parameterized over several permutations of auto-command event types, auto-command patterns and minor variations of the actual commands run. Specifically, I tried both direct and indirect calls to echom. (Indirect: echom put in a function and the autocommand calls the function.) For the indirect cases I also wrapped the echom calls in redir so, in theory anyways, the messages would appear in both :mess command output and in a temporary file.

Results didn't turn up any surprises...

Vim (and gvim) consistently showed echom messages in real-time and when viewed with :mess for all tested event types as long as the pattern used was valid. For the indirect command calls all messages also showed up in the redir files.

Neovim had less consistent results. For event type BufEnter everything worked exactly as it did for vim. For the FileType, BufRead and BufReadPre events the messages never showd up real-time or in :mess output. The only cases that the echom call could be verified to have occurred at all with these events is with the indirect/redir test variations. In those cases the echom output always appeared in the redir file.

Anyways, I believe this concludes matters as far as StackExchange activities go. Next step, if someone wants to move things forward, would be to see what the neovim maintainers have to say about it.

Final Update: Apparently this is due to a different default than Vim for 'shortmess' and removing F from its value will match Vim's behavior. Doesn't make me feel too much better about it as the behavior (e.g. affecting this autocmd but not that) is apt to cause confusion. (There have been a number of bug reports filed over this thing.)

| improve this answer | |
  • I tried it with filetype on (which I think is supposed to be on by default in Neovim, that's why I didn't think it mattered) and it didn't work. I also have a much more complicated .vimrc file that I used for vim, and when I coppied into my init.vim, my FileType autocommands didn't work. – Mason Jan 24 at 1:46
  • What's in the Session.vim file? Is it easy to eyeball what it may be adding that you don't have by default? BTW, are you testing with a known filetype? – B Layer Jan 24 at 1:47
  • I'm not seeing anything. But I can tell you that it only works right after I source it. If I source it and then go to open another file, that other file won't trigger the autocommand. – Mason Jan 24 at 1:51
  • In my main file I have them in a group, I just wanted to make it as simple as possible. Also it does work when I manually change the filetype, so it looks like the problem is it's just not getting fired when the file loads. – Mason Jan 24 at 2:02
  • Let us continue this discussion in chat. – Mason Jan 24 at 2:03
1

In the Neovim FAQ Here it explains by default Neovim has shortmess+=F, which turns off messages during file operations. Add shortmess-=F and then it will perform the same as original Vim.

| improve this answer | |

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.