h0hc4q
Last Updated: March 28, 2017
·
5.034K
· copenhas
Bced6483c146fb54e5a24cb16deab1ca

Zsh rerun last command with search/replace

Heads up, you can rerun the last command with a replace in one swoop:

!!:s/find it/replace it/

That'll do the first match, but to replace all matches on the line:

!!:gs/gotta/replace them all/

If that's not short enough for you (this is UNIX command line after all), rerun last command and perform a replace on first match:

^find it^replace it

Oh, two more things...

it's stackable:

!!:s/find this/replace it/:s/find that/replace it too/

same thing works with variables:

echo ${PATH:gs/copenhas/YOU/}
Say Thanks
Respond
Filed Under