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 contextsthrow— 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=9for even more information about what Vim is doing - In Neovim Lua,
:set debug=msgstill applies to Vimscript called from Lua - The
throwflag is useful when writing plugins that need to catch built-in errors: it converts them into exceptions that:catchcan intercept