How to run vim command silently without interrupting bash script

28 Views Asked by At

I run the following vim search-and-replace command within a bash script:

#!/bin/bash
...
vim -c ':%s/candle/light/g | write | quit' file.txt
...

The command above opens a file, replaces every 'candle' with 'light', save and quit.

The problem is that when no word 'candle' is found within that file, the whole script is interrupted. And I can see vim saying:

E486: Pattern not found: candle

How can I run the command silently without interrupting the bash script?

0

There are 0 best solutions below