zsh-users
 help / color / mirror / code / Atom feed
From: "Jérémie Roquet" <arkanosis@gmail.com>
To: meino.cramer@gmx.de
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: s/pattern/pattern/g on the commandline ?
Date: Sun, 26 Feb 2012 16:17:00 +0100	[thread overview]
Message-ID: <CAFOazAP+twKNxWVhO6AO+0qHyd_04X3rQTRnOeO9Yi88OVuDRA@mail.gmail.com> (raw)
In-Reply-To: <20120226075234.GB3020@solfire>

Hi,

2012/2/26  <meino.cramer@gmx.de>:
> ...an additional question:
>
> Suppose I had entered such an ugly looooong commandline about two days
> ago. I did not remember when it was and what the context was.
> And: I have a very looong history file.
>
> I want to recycle that line and do the s//g-trick on it to get a shiny
> new fresh commmandline for the next action.

If the command in your long line is unusual (let's say “makecoffee”),
you could use:

!makecoffee:gs/<before>/<after>

> When I press ^r<pattern> I easily can find that line, it will
> displayed instantly but without its numbering. In the moment the
> commandline is displayed I loose the ability to do the s//g-trick.
>
> Is there a way to browse the commandlines like with ^r only to get its
> numbering to apply the s//g-trick to the choosen line ?

Hacking history-incremental-pattern-search-backward is an option, but
that wouldn't be easy.

Instead, you could use:

fc -lm <pattern>

…to list previous commands matching the pattern, with their numbers.

Also, what I do in non trivial cases, is either:
 - use edit-command-line as pointed out by Phil: you just have to
ctrl+r the line you want and then edit it using a real text editor, or
 - use a custom widget to run sed (or awk, or perl, or…) on the
current line : you just have to ctrl+r the line you want then to use
whatever key you've bound the widget to to run sed on it.

If you put this in your .zshrc:

function sed-line ()
{
   read-from-minibuffer 'Sed: '
   if [[ -n $REPLY ]]; then
      BUFFER=`echo $BUFFER | sed $REPLY`
   fi
}
zle -N sed-line
bindkey "^[e" sed-line

… you can then use meta-e to run a sed command on the line currently
being edited in your shell.

Best regards,

-- 
Jérémie


  parent reply	other threads:[~2012-02-26 15:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-25 18:24 meino.cramer
2012-02-25 18:35 ` Jérémie Roquet
2012-02-25 18:41   ` Jérémie Roquet
2012-02-25 18:46     ` Moritz Bunkus
2012-02-25 19:03       ` Damien Thébault
2012-02-25 19:19         ` Jérémie Roquet
2012-02-25 19:36           ` Moritz Bunkus
2012-02-25 19:24       ` Phil Pennock
2012-02-25 20:30         ` Christoph (Stucki) von Stuckrad
2012-02-26 18:32       ` Bart Schaefer
2012-02-27  3:14         ` Darryl Zurn
     [not found]     ` <20120226075234.GB3020@solfire>
2012-02-26 15:17       ` Jérémie Roquet [this message]
     [not found]     ` <20120227041300.GA3063@solfire>
2012-02-28 13:09       ` Jérémie Roquet
2012-02-29 13:48         ` Christoph (Stucki) von Stuckrad
2012-02-29 15:55           ` Bart Schaefer
2012-02-27 10:38 ` Peter Stephenson
2012-03-29 12:06   ` Vincent Lefevre
2012-03-29 20:23     ` Peter Stephenson

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=CAFOazAP+twKNxWVhO6AO+0qHyd_04X3rQTRnOeO9Yi88OVuDRA@mail.gmail.com \
    --to=arkanosis@gmail.com \
    --cc=meino.cramer@gmx.de \
    --cc=zsh-users@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).