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

How do I make Vim show error messages that are silently swallowed inside :silent! or :try blocks?

Answer

:set debug=msg

Explanation

When troubleshooting mappings or scripts that use :silent!, errors disappear without a trace. Setting debug=msg forces Vim to print those suppressed error messages, making it far easier to diagnose problems in Vimscript, plugins, and complex mappings.

How it works

The debug option accepts a comma-separated list of flags:

  • msg — Report error messages that occur inside :silent!, :try/:catch, and other error-suppressing contexts
  • throw — Turn built-in errors into catchable exceptions (useful for Vimscript exception handling)
  • beep — Sound a beep whenever messages are shown

The most useful flag day-to-day is msg. With it set, a mapping like:

noremap <leader>x :silent! call MyBrokenFunc()<CR>

will now print the error from MyBrokenFunc() instead of silently failing.

Example

:set debug=msg
:silent! call nonexistent_function()
" Now prints: E117: Unknown function: nonexistent_function

Without debug=msg, the :silent! swallows the error completely.

Tips

  • Reset with :set debug= (empty string) once you are done debugging
  • Combine with :set verbose=9 for even more information about what Vim is doing
  • In Neovim Lua, :set debug=msg still applies to Vimscript called from Lua
  • The throw flag is useful when writing plugins that need to catch built-in errors: it converts them into exceptions that :catch can intercept

Next

How do I execute Ctrl-W window commands from a Vimscript mapping or function without using :normal?