Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

RE: Very useful !#^



Excellent summary, thanks much.

-----Original Message-----
From: news [mailto:news@xxxxxxxxxxxxx] On Behalf Of zzapper
Sent: Friday, August 03, 2007 10:29 AM
To: zsh-users@xxxxxxxxxx
Subject: RE: Very useful !#^

Seth
the # stands for current line

A summary :

# History Substitution Summary
#For CURRENT line that you are editing (the # designates current line)
# Remember Tab will expand the following

!#:0    current command
!#^     first parameter
!#:1    first parameter
!#:1-4  first 4 parameters
!#$     last parameter
!#*     all parameters
!#$:s/bash/zsh perform substitution on previous parameter

cp longfilename.php backup_!#$

#For Previous Command (for comparison)
!-1     repeat whole command
!!      repeat (shortcut)
!:0     command
!^      first parameter
!:1     first parameter
!:1-4   first 4 parameters
!$      last parameter
!*      all parameters
!!:s/bash/zsh

For last but one command
!-2     repeat last but one command
!-2:2   second parameter of second but last command
etc
For history command 42
!42

<hr width=80%>
!:0 is the previous command name
!^, !:2, !:3, !$ are the arguments
!* is all the arguments
!-2, !-3,  are earlier commands
!-2^, !-2:2, !-2$, !-2* are earlier parameters

# duplicate previous line (as example)
!:0 !^ !:2 !:3 !$   (of course you could do !!)

# duplicate nth previous line where n=1..n

!-n:0 !-n^ !-n:2 !-n:3 !-n$

cd !$:h  (remove file name)
cat !!:t (only file name)




-- 
zzapper
http://successtheory.com/tips/zshtips.html





Messages sorted by: Reverse Date, Date, Thread, Author