From b496b83068c026caf88b68ebcd4d798a2f1165eb Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 8 Aug 2015 12:14:10 -0500 Subject: [PATCH] Add Global Substitution On The Previous Command as a zsh til. --- README.md | 1 + ...al-substitution-on-the-previous-command.md | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 zsh/global-substitution-on-the-previous-command.md diff --git a/README.md b/README.md index e390ddb..dd8bf24 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,7 @@ smart people at [Hashrocket](http://hashrocket.com/). - [Clear The Screen](zsh/clear-the-screen.md) - [Create A File Descriptor with Process Substitution](zsh/create-a-file-descriptor-with-process-substitution.md) - [Do Not Overwrite Existing Files](zsh/do-not-overwrite-existing-files.md) +- [Global Substitution On The Previous Command](zsh/global-substitution-on-the-previous-command.md) - [Killing A Frozen SSH Session](zsh/killing-a-frozen-ssh-session.md) - [List All The Say Voices](zsh/list-all-the-say-voices.md) - [Repeat Yourself](zsh/repeat-yourself.md) diff --git a/zsh/global-substitution-on-the-previous-command.md b/zsh/global-substitution-on-the-previous-command.md new file mode 100644 index 0000000..bbd0a1c --- /dev/null +++ b/zsh/global-substitution-on-the-previous-command.md @@ -0,0 +1,28 @@ +# Global Substitution On The Previous Command + +Let's say we just executed the following command: + +```bash +$ grep 'foo' foo.md +``` + +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 `bar.md`. The `^` +trick won't quite work here. + +```bash +$ ^foo^bar +$ grep 'bar' foo.md +``` + +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. + +```bash +$ !!gs/foo/bar +$ grep 'bar' bar.md +``` + +For a short command like this, we haven't gained much. However, for large +commands that span the length of your terminal, this can definitely save you +a little trouble.