How do I write a file in Vim without triggering BufWritePre or other write autocmds?
Answer
:noautocmd w
Explanation
The :noautocmd modifier runs any Ex command while suppressing all autocmd events for its duration. This is invaluable when you have write-time hooks — formatters, trailing-whitespace strippers, or linters — and you need to save in an intermediate or deliberately unformatted state without triggering them.
How it works
:noautocmd {cmd}— executes{cmd}with all autocommand events disabled:noautocmd w— writes the buffer without firingBufWritePre,BufWritePost, or any otherBufWrite*events- The suppression is temporary and only lasts for that single command; your autocmds continue working normally for all subsequent saves
Example
Imagine your vimrc runs a formatter on save:
autocmd BufWritePre *.py :Black
Normally :w reformats the file. To save without reformatting:
:noautocmd w
The file is written as-is. The next regular :w will still invoke :Black.
Tips
- Works with any command, not just
:w::noautocmd e!reloads without triggeringBufReadPost :noautocmd wqto write-and-quit without triggering any write hooks- Combine with ranges:
:noautocmd 1,50w partial.txtto write a range without events - For persistent suppression during a script, use
set eventignore=alland unset afterward — but prefer:noautocmdfor single commands