Bash – Command line in vi mode: replace all

bashvi

How do I replace globally from the command line in vi mode. It seems like I can't use ex commands by prefixing with :, so what do I do instead.

for instance if I want to replace all \ with / in a command…

Best Answer

I'd use the bash history mechanism:

$ echo 'foo\bar\baz'
foo\bar\baz
$ !!:gs/b/B/
echo 'foo\Bar\Baz'
foo\Bar\Baz

However, I can't seem to get it to replace backslashes

$ echo 'foo\bar\baz'
foo\bar\baz
$ !!:gs/\\/\//
bash: :gs/\\/\//: substitution failed
Related Question