You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As discussed on Twitter, here are some shortcuts I use regularly in zsh that made my life easier. Note that not all of them apply (i.e. work) depending on the zsh binding mode, e.g. default, emacs/vi, etc. What I am describing here is out of the box UX with zsh (my env is oh-my-zsh on OSX).
search/replace a command from history
Say you executed the following command:
$ echo "Hi, I love BASH"
Using zsh's history search & replace functionality, one can easily change a string (or character, etc.):
$ !!:s/BASH/ZSH <TAB>
This will change BASH to ZSH. Additional functionality:
use gs instead of s to replace multiple occurrences
!! is the last command executed; but you can also use !-2 to get the second last (i.e. !-n n-last) command
if you want to undo a replacement (or any substitution) use CTRL+_ (underscore, that is SHIFT+ -)
get --help faster with zsh
Say you want to see all CLI flags for brew upgrade. Instead of brew upgrade --debug or searching man pages, it's as easy as:
$ brew upgrade --<TAB>
Kill processes faster
Instead of killing a process by finding its PID first, why not use zsh?
# kill a Google Chrome process by just typing the first characters
$ kill Goo<TAB>
Edit that super long command in <your favorite editor>
Say you have this crazy long command and need to replace one character in the middle of the line. What you want is to open your favorite $EDITOR and just do it. Well, zsh got you covered:
You want to fix this texxt typo, so while you have this line in your terminal just press CTRL-X-E (more precisely CTRL-X followed by CTRL-E). This will open the line in your $EDITOR, where you can make the change, save it (eg :wq in vi) and you will return to your terminal where you can then execute the command.
Stash the current command line
Say you would like to clear the screen before executing the command you already typed in your prompt. But you don't want to erase that long line. So instead of commenting out the line, copy & pasting it back and forth, why not use zsh to stash it :) ?
# this is the line we would like to stash
$ curl -s -i -k -d '{"texxt":"hello world"}' https://some.server.com
While you're in the prompt, just hit ESC-q. Then type the intermediate command you want to execute, e.g. clear (the screen). And after that, zsh will restore the stashed command.
The text was updated successfully, but these errors were encountered:
Thanks for opening the issue. These are all great tips and I think they are all covered in various sections except for team completion on kill.
Check out the history, line movement, and widgets sections. Let me know if you think the explainations of those keyboard shortcuts aren't clear. On some cases I r bound the widgets to different keyboard shortcuts because I didn't look up what the defaults were. (I should have)
Hi Justin, create work here!
As discussed on Twitter, here are some shortcuts I use regularly in
zsh
that made my life easier. Note that not all of them apply (i.e. work) depending on the zsh binding mode, e.g. default, emacs/vi, etc. What I am describing here is out of the box UX with zsh (my env is oh-my-zsh on OSX).search/replace a command from history
Say you executed the following command:
Using zsh's history search & replace functionality, one can easily change a string (or character, etc.):
This will change
BASH
toZSH
. Additional functionality:gs
instead ofs
to replace multiple occurrences!!
is the last command executed; but you can also use!-2
to get the second last (i.e. !-n n-last) commandCTRL+_
(underscore, that isSHIFT+ -
)get
--help
faster with zshSay you want to see all CLI flags for
brew upgrade
. Instead ofbrew upgrade --debug
or searching man pages, it's as easy as:Kill processes faster
Instead of killing a process by finding its PID first, why not use zsh?
Edit that super long command in <your favorite editor>
Say you have this crazy long command and need to replace one character in the middle of the line. What you want is to open your favorite
$EDITOR
and just do it. Well, zsh got you covered:You want to fix this
texxt
typo, so while you have this line in your terminal just pressCTRL-X-E
(more preciselyCTRL-X followed by CTRL-E
). This will open the line in your $EDITOR, where you can make the change, save it (eg:wq
in vi) and you will return to your terminal where you can then execute the command.Stash the current command line
Say you would like to clear the screen before executing the command you already typed in your prompt. But you don't want to erase that long line. So instead of commenting out the line, copy & pasting it back and forth, why not use zsh to stash it :) ?
While you're in the prompt, just hit
ESC-q
. Then type the intermediate command you want to execute, e.g.clear
(the screen). And after that, zsh will restore the stashed command.The text was updated successfully, but these errors were encountered: