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

How do I run a Vim command and suppress all its output messages and error messages?

Answer

:silent!

Explanation

The :silent! modifier runs an Ex command without displaying any output or error messages. The plain :silent form suppresses normal output (like "file.txt" 42L, 1234B written) but still shows errors if a command fails. Adding ! makes it ignore errors too, allowing the next command to run regardless of whether this one succeeded.

How it works

  • :silent {cmd} — suppresses messages printed by the command, but errors still appear.
  • :silent! {cmd} — suppresses both messages and errors; the command is attempted but failures are discarded silently.
  • Both forms update the v:errmsg variable, so you can still check whether an error occurred afterwards.

Example

In a mapping that writes the file, suppress the confirmation message:

nnoremap <leader>w :silent! w<CR>

Without :silent!, pressing <leader>w would briefly display:

"notes.md" 3L, 47B written

With :silent! w, the write happens invisibly.

For conditional logic — try to source a file if it exists, ignore the error otherwise:

silent! source ~/.vim/local.vim

Tips

  • Use :silent! in mappings to keep the command line clean and avoid the Press ENTER prompt.
  • Combine with :update (which only writes if the buffer is modified) for a noise-free auto-save: silent! update.
  • Use :silent (without !) when you want to see errors but not routine output — helpful for debugging mappings.
  • After a silent command, check v:errmsg to detect failures: if v:errmsg != '' | echo 'Error!' | endif.

Next

How do I remove a word I accidentally added to my Vim spell dictionary?