Nix: Global Substitution On The Previous Command

less than 1 minute read

Let’s say we just executed the following command:

grep 'foo'

It gave us the information we were looking for and now we want to execute a similar command to find the occurrences of bar in The ^ trick won’t quite work here.

$ ^foo^bar<tab>
grep 'bar'

What we need is a global replace of foo in our previous command. The !! command can help when we sprinkle in some sed-like syntax.

$ !!gs/foo/bar<tab>
grep 'bar'

For a short command like this, we haven’t gained much. However, for large commands that span the length of the terminal, this can definitely save us a little trouble.

Via jbranchaud/til.

Tags: ,