vimtricks.wiki Concise Vim tricks, one at a time.

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 :windo or :bufdo to 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 :noa to check whether an autocmd is responsible.
  • :doautocmd can 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_autocmds with the group option, or wrapping code in vim.api.nvim_create_augroup with clear = true.

Next

How do I open the directory containing the current file in netrw from within Vim?