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

How do I run a Vim command without triggering any autocommands?

Answer

:noautocmd write

Explanation

The :noautocmd modifier (abbreviated :noa) runs any subsequent Ex command while temporarily disabling all autocommand events. This is useful when you need to write a file, open a buffer, or run a command without side effects from BufWritePre, BufEnter, FileType, or other autocmds that would otherwise fire.

How it works

:noautocmd {command} executes {command} with eventignore=all in effect for the duration of that command only. Autocommands resume firing normally after the command completes.

Common uses:

  • :noautocmd write — save a file without triggering format-on-save, linters, or other BufWritePre/BufWritePost hooks
  • :noautocmd edit file.txt — open a file without triggering BufEnter or FileType autocmds
  • :noautocmd bufdo %s/old/new/g — run a bulk substitution across all buffers without repeatedly triggering per-buffer autocmds

Example

If your config has a format-on-save autocmd:

autocmd BufWritePre * lua vim.lsp.buf.format()

But you want to save the raw unformatted version:

:noautocmd write

The file is written to disk, but the LSP formatter never runs.

Tips

  • The abbreviation :noa works everywhere :noautocmd does: :noa w saves without autocmds
  • :set eventignore=all has the same effect globally until you unset it — :noautocmd is scoped to a single command and is therefore safer
  • Combine with :silent to suppress messages too: :silent noautocmd write
  • Useful in scripts and mappings where autocmd side effects would cause slowness or unwanted behaviour

Next

How do I match a pattern only when it is preceded or followed by another pattern, without including that context in the match?