From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 912 invoked by alias); 15 Jul 2014 07:47:40 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 32864 Received: (qmail 1194 invoked from network); 15 Jul 2014 07:47:36 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <140714234638.ZM29435@torch.brasslantern.com> Date: Mon, 14 Jul 2014 23:46:38 -0700 In-reply-to: <874myk3ocp.fsf@debian.uxu> Comments: In reply to Emanuel Berg "implicit previous command, only state what should change" (Jul 14, 12:06am) References: <874myk3ocp.fsf@debian.uxu> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Emanuel Berg , zsh-workers@zsh.org Subject: Re: implicit previous command, only state what should change MIME-version: 1.0 Content-type: text/plain; charset=us-ascii To add to what's already been said ... On Jul 14, 12:06am, Emanuel Berg wrote: } } Is there a way to tell zsh to "execute the previous } command again, only substitute the first argument for } user-emacs-directory"? Like } } $ !!:1->user-emacs-directory There's no shorthand quite like for arbitrary word positions. To drop just the *last* word, you can use !!:- However, you can always do the obvious: zsh% !:0 user-emacs-directory !:2* Or for e.g. the third word: zsh% !:0-2 new-third-word !:4* The default event is the previous command so you don't need to double the "!" -- but note that subsequent "!" refer to the same command as the preceding reference. So if you want to swap the second word of the fifth preceding command: zsh% !-5:0-1 new-second-word !:3* There, because !-5 has already selected the fifth previous command, !:3* selects the third and remaining words of that same command. You can automate this for some simple cases (the following assumes you are using the default non-vi key bindings): bindkey -s ^X1 '^U!!:0 \e!^ !!:2*^X^X\e!' bindkey -s ^X2 '^U!!:0-1 \e!^ !!:3*^X^X\e!' bindkey -s ^X3 '^U!!:0-2 \e!^ !!:4*^X^X\e!' bindkey -s ^X4 '^U!!:0-3 \e!^ !!:5*^X^X\e!' bindkey -s ^X5 '^U!!:0-4 \e!^ !!:6*^X^X\e!' With this, typing ctrl+x 1 will re-insert the previous line with the first argument omitted, leaving the cursor where the new first argument should be typed. Similarly for ctrl+x 2 through 5, though they don't work quite ideally if there are no arguments following the one you're replacing (try it to see what I mean).