I added a function in my .vimrc that's just few search and replace commands. However if one of the patterns is not found I get an error message that I need to enter through. How can I suppress this?
+1
A:
You might use silent:
:silent %s/x/y/g
or, if you need to do string manipulation to determine the strings to search and replace:
exec ":silent %s/x/" . varName . "/g"
I'm not 100% sure, but I think that silent
only works in scripts.
Paolo Tedesco
2009-06-25 11:48:22
+5
A:
You can either use :silent
or :silent!
as a prefix to any command or you can add the 'e' option to the substitute, which is often easier.
:%s/x/y/ge
:silent! %s/x/y/g
:silent %s/x/y/g
For more information, see
:help :silent
:help :s_flags
The information on the e
flag is a few paragraphs down from the :s_flags
help.
Al
2009-06-25 12:22:44
Silent didn't work in my script, but the 'e' flag did
nearly_lunchtime
2009-06-25 13:02:56