J. Doe
J. Doe

Reputation: 93

Vim - autocommands ignored while in autocommand code

As the title says, are autocommands not triggering while executing an autocommand? For example, I have tested opening a new window with 'new' inside a VimEnter autocommand and it didn't trigger the WinNew autocommand. On the other hand, when I just put 'new' in the .vimrc file, it triggers the WinNew autocommand.

Upvotes: 2

Views: 265

Answers (1)

L3viathan
L3viathan

Reputation: 27273

Quoting from autocmd.txt:

By default, autocommands do not nest. If you use ":e" or ":w" in an autocommand, Vim does not execute the BufRead and BufWrite autocommands for those commands. If you do want this, use the "nested" flag for those commands in which you want nesting. For example:

:autocmd FileChangedShell *.c nested e!

The nesting is limited to 10 levels to get out of recursive loops.

Upvotes: 2

Related Questions