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

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 firing BufWritePre, BufWritePost, or any other BufWrite* 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 triggering BufReadPost
  • :noautocmd wq to write-and-quit without triggering any write hooks
  • Combine with ranges: :noautocmd 1,50w partial.txt to write a range without events
  • For persistent suppression during a script, use set eventignore=all and unset afterward — but prefer :noautocmd for single commands

Next

How do I make the = operator use an external formatter instead of Vim's built-in indentation?