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 otherBufWritePre/BufWritePosthooks:noautocmd edit file.txt— open a file without triggeringBufEnterorFileTypeautocmds: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
:noaworks everywhere:noautocmddoes::noa wsaves without autocmds :set eventignore=allhas the same effect globally until you unset it —:noautocmdis scoped to a single command and is therefore safer- Combine with
:silentto suppress messages too::silent noautocmd write - Useful in scripts and mappings where autocmd side effects would cause slowness or unwanted behaviour