Here are a few zsh tricks that I learned (and enjoy using) recently:
The basics - use !! to retrieve last command#
tail /var/log/message
!!plaintextThe not so basic - get last parameter of last command with !$#
mkdir new_folder
cd !$ # after this command you will be in folder new_folderplaintextGet all parameters from the last command with !*#
diff src/file1 dest/
cp !*plaintextThe pretty awsome - substitution with !!:s/from/to or !!:gs/from/to#
vi src/en/file.txt
!!:s/en/frplaintextdiff src/en/file.txt dest/en/file.txt
!!:gs/en/fr # g for global substitutionplaintextEven better with ^#
vi src/en/file.txt
^en^fr
diff src/en/file.txt dest/en/file.txt
^en^fr^:G plaintextSwitching 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
cd myproject1 myproject2plaintextor even
cd 1 2plaintextBatch renaming with zmv#
autoload zmv
zmv '(*).txt' '$1.dat' # change *.txt to *.datplaintextsee more zmv examples at http://zshwiki.org/home/builtin/functions/zmv ↗