Send vim a separate quit command with -c 'q'
, which it will execute after the search/replace (works on my vim version 7.3.315
):
ex -c 'g/^[#][[:space:]]*$/d|x' -c 'q' file.txt
Also note ex
appears to execute the commands in the order which they appear in ARGV, so:
ex -c 'q' -c 'g/^[#][[:space:]]*$/d|x' file.txt
Quits before doing the search/replace.