How do I run a command without triggering any autocommands, such as saving without auto-formatting?
Answer
:noautocmd {cmd}
Explanation
The :noautocmd (abbreviated :noa) prefix suppresses all autocommand events for the duration of the command that follows it. This is essential when you need to bypass behaviors wired up through autocmds — such as auto-formatters, linters, or file-type detection — without permanently disabling them.
How it works
Prepend :noautocmd (or :noa) to any Ex command:
:noautocmd w " write without triggering BufWritePre/BufWritePost
:noautocmd e file " edit without triggering BufEnter/BufReadPost
:noa windo e " cycle windows without triggering WinEnter events
All autocommands — including those defined by plugins — are silenced for the execution of the command. They resume normally afterwards.
Example
If a BufWritePre autocmd runs a formatter on every save, you can bypass it for one write:
:noautocmd write
Or use the short form:
:noa w
Tips
- Combine with
:windoor:bufdoto iterate over windows or buffers without autocmds firing on every switch::noa windo set wrap. - Useful for performance debugging: if Vim feels slow after an operation, try it with
:noato check whether an autocmd is responsible. :doautocmdcan manually fire a specific event when you want to trigger autocmds on demand after having suppressed them.- Neovim's Lua equivalent is
vim.api.nvim_exec_autocmdswith thegroupoption, or wrapping code invim.api.nvim_create_augroupwithclear = true.