zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: <zsh-users@zsh.org>
Subject: Re: s/pattern/pattern/g on the commandline ?
Date: Mon, 27 Feb 2012 10:38:44 +0000	[thread overview]
Message-ID: <20120227103844.1de5405d@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20120225182450.GA31597@solfire>

On Sat, 25 Feb 2012 19:24:50 +0100
<meino.cramer@gmx.de> wrote:
> Is there any way to submit commands like
> 's/<searched>/<replacement>/g' for being applied the whole commandline
> in one go?

Just as a postscript, it's worth noting the ZLE widgets replace-string
(which can also be loaded under the names replace-pattern or
replace-regexp) and replace-string-again.  This allows you to do this
interactively from the command line.  See the zshcontrib manual page.

I use


# actually autoloaded
zlewidget() {
  # bindkey KEY to new WIDGET, possibly implemented by optional FUNCTION.
  # FUNCTION defaults to WIDGET and will be marked for autoload -Uz.

  local key=$1
  local widget=$2
  local function=${3:-$2}

  autoload -Uz $function
  zle -N $widget $function
  bindkey $key $widget
}
zlewidget "\e%" replace-regexp replace-string
zlewidget '\e&' replace-regexp-again replace-string-again


(though in fact I don't tend to use \e& because (i) I rarely need to
replace the same thing multiple times (ii) I can't remember what the
last thing I replaced is anyway.)

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog


  parent reply	other threads:[~2012-02-27 10:41 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
     [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 [this message]
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=20120227103844.1de5405d@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.com \
    --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).