You can silence individual commands inside a function by prepending
:silent! just as well, so either
:silent! execute or
:execute 'silent! %s... would do.
However, you don't need any of this, because
:substitute understands a
/e flag that suppresses any errors resulting from no pattern matches (cp.
Also, you only need
:execute when you need to interpolate variable contents into a command. Your substitution uses a constant pattern, so you're just making the command more complex (because of the doubling of backslashes) without any benefit:
Additional comments on style
- You don't need the
:call; this is only needed in (interactive or in a mapping) normal mode to switch to command-line mode. As
:autocmd already takes an Ex command, it's superfluous.
== 0 is superfluous as well.
'readonly' is a boolean flag that evaluates to
0 if unset, and
0 evaluates to false in a conditional.