Here are a few zsh tricks that I learned (and enjoy using) recently:
The basics - use !! to retrieve last command
1 | tail /var/log/message |
The not so basic - get last parameter of last command with !$
1 | mkdir new_folder |
Get all parameters from the last command with !*
1 | diff src/file1 dest/ |
The pretty awsome - substitution with !!:s/from/to or !!:gs/from/to
1 | vi src/en/file.txt |
diff src/en/file.txt dest/en/file.txt
!!:gs/en/fr # g for global substitution
Even better with ^
1 | vi src/en/file.txt |
Switching between directories with similar structure (added Dec 7, 2013)
let’s say you are in ~/dev/myproject1/src/lib/, and you want to cd to ~/dev/myproject2/src/lib/, all you need to do is
1 | cd myproject1 myproject2 |
or even
1 | cd 1 2 |
Batch renaming with zmv
1 | autoload zmv |
see more zmv examples at http://zshwiki.org/home/builtin/functions/zmv