zsh-users
 help / color / mirror / code / Atom feed
* tweaking insert-last-word behavior
@ 2009-11-09  5:11 Andy
  2009-11-09 13:11 ` Mikael Magnusson
  2009-11-09 16:45 ` Wayne Davison
  0 siblings, 2 replies; 3+ messages in thread
From: Andy @ 2009-11-09  5:11 UTC (permalink / raw)
  To: zsh-users

Hi -

Is there some way to induce selective amnesia in 'insert-last-word'?

Specifically, I get a lot of use out of aliases like
   alias -g M='| more'

However, if my previous command was
   % grep bar foo.txt M
and I'm now breathlessly typing out my next clever interrogation of 
foo.txt, the letter "M" is never, of course, what I actually mean to 
insert when I hit 'ESC-.'

I suspect that many shell users make this mistake at least occasionally 
when a pager is invoked at the end of a command - regardless of whether 
it's aliased.

Ideally I'd love to hear that there's an undocumented 'alias' flag that 
means "invisible to insert-last-word". I presume that'd be a lousy general 
solution to the issue, however.

I assume I could remap it so it compares !$ against a list of strings like 
'M' and alternately inserts word n-1. Beyond that feeling rather kludgy, 
I'm not quite sure how to do that; it wasn't obvious to me, for instance, 
how one references the word at !(n-1) with zsh.

Maybe I'm thinking about the problem in the wrong way. Is there an easy 
solution?

Thanks,

Andy


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: tweaking insert-last-word behavior
  2009-11-09  5:11 tweaking insert-last-word behavior Andy
@ 2009-11-09 13:11 ` Mikael Magnusson
  2009-11-09 16:45 ` Wayne Davison
  1 sibling, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2009-11-09 13:11 UTC (permalink / raw)
  To: Andy Sisson; +Cc: zsh-users

2009/11/9 Andy <andy@miranda.org>:
> Hi -
>
> Is there some way to induce selective amnesia in 'insert-last-word'?
>
> Specifically, I get a lot of use out of aliases like
>  alias -g M='| more'
>
> However, if my previous command was
>  % grep bar foo.txt M
> and I'm now breathlessly typing out my next clever interrogation of foo.txt,
> the letter "M" is never, of course, what I actually mean to insert when I
> hit 'ESC-.'
>
> I suspect that many shell users make this mistake at least occasionally when
> a pager is invoked at the end of a command - regardless of whether it's
> aliased.
>
> Ideally I'd love to hear that there's an undocumented 'alias' flag that
> means "invisible to insert-last-word". I presume that'd be a lousy general
> solution to the issue, however.
>
> I assume I could remap it so it compares !$ against a list of strings like
> 'M' and alternately inserts word n-1. Beyond that feeling rather kludgy, I'm
> not quite sure how to do that; it wasn't obvious to me, for instance, how
> one references the word at !(n-1) with zsh.
>
> Maybe I'm thinking about the problem in the wrong way. Is there an easy
> solution?

I have copy-earlier-word bound to the key to the left of insert-last-word, which
lets me select any word of any previous line quite easily.

autoload -U copy-earlier-word
zle -N copy-earlier-word

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: tweaking insert-last-word behavior
  2009-11-09  5:11 tweaking insert-last-word behavior Andy
  2009-11-09 13:11 ` Mikael Magnusson
@ 2009-11-09 16:45 ` Wayne Davison
  1 sibling, 0 replies; 3+ messages in thread
From: Wayne Davison @ 2009-11-09 16:45 UTC (permalink / raw)
  To: Andy Sisson; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 963 bytes --]

On Sun, Nov 8, 2009 at 9:11 PM, Andy <andy@miranda.org> wrote:

> However, if my previous command was
>  % grep bar foo.txt M
> and I'm now breathlessly typing out my next clever interrogation of
> foo.txt, the letter "M" is never, of course, what I actually mean to insert
> when I hit 'ESC-.'
>

I use smart-insert-last-word with a match directive:

autoload -U smart-insert-last-word
zle -N insert-last-word smart-insert-last-word
zstyle :insert-last-word match '[^,]??*'

Since I want words that are at least 3 letters long and don't begin with a
comma (all my global aliases use a leading comma, such as ",l" for "| less",
",f" for "| fgrep", etc.).  Since anything really short is not really worth
using insert-last-word for anyway, this tends to do what I expect.  Note
that if no qualifying words are found on a line, smart-insert-last-word just
returns the last word, so don't let that fool you into thinking there is a
bug when there is not.

..wayne..

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-11-09 17:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-09  5:11 tweaking insert-last-word behavior Andy
2009-11-09 13:11 ` Mikael Magnusson
2009-11-09 16:45 ` Wayne Davison

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