mirror of
https://github.com/jbranchaud/til
synced 2026-01-06 16:48:01 +00:00
Add Global Substitution On The Previous Command as a zsh til.
This commit is contained in:
@@ -194,6 +194,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
- [Clear The Screen](zsh/clear-the-screen.md)
|
- [Clear The Screen](zsh/clear-the-screen.md)
|
||||||
- [Create A File Descriptor with Process Substitution](zsh/create-a-file-descriptor-with-process-substitution.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)
|
- [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)
|
- [Killing A Frozen SSH Session](zsh/killing-a-frozen-ssh-session.md)
|
||||||
- [List All The Say Voices](zsh/list-all-the-say-voices.md)
|
- [List All The Say Voices](zsh/list-all-the-say-voices.md)
|
||||||
- [Repeat Yourself](zsh/repeat-yourself.md)
|
- [Repeat Yourself](zsh/repeat-yourself.md)
|
||||||
|
|||||||
28
zsh/global-substitution-on-the-previous-command.md
Normal file
28
zsh/global-substitution-on-the-previous-command.md
Normal file
@@ -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<tab>
|
||||||
|
$ 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<tab>
|
||||||
|
$ 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.
|
||||||
Reference in New Issue
Block a user