zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Emanuel Berg <embe8573@student.uu.se>, zsh-workers@zsh.org
Subject: Re: implicit previous command, only state what should change
Date: Mon, 14 Jul 2014 23:46:38 -0700	[thread overview]
Message-ID: <140714234638.ZM29435@torch.brasslantern.com> (raw)
In-Reply-To: <874myk3ocp.fsf@debian.uxu>

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).


  parent reply	other threads:[~2014-07-15  7:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-13 22:06 Emanuel Berg
2014-07-13 22:24 ` Frank Terbeck
2014-07-13 22:50   ` Emanuel Berg
2014-07-14  2:08     ` Mikael Magnusson
2014-07-14 13:09       ` Emanuel Berg
2014-07-15  6:46 ` Bart Schaefer [this message]
2014-07-15 15:42   ` Emanuel Berg
2014-07-15 16:58 ` Peter Stephenson
2014-07-16  0:36   ` Emanuel Berg
2014-07-16 13:54     ` Peter Stephenson
2014-07-16 20:45       ` Emanuel Berg
2014-07-16 20:53         ` Bart Schaefer
2014-07-16 21:08           ` Emanuel Berg
2014-07-17  8:17         ` Peter Stephenson
2014-07-17 13:01           ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=140714234638.ZM29435@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=embe8573@student.uu.se \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).