zsh-users
 help / color / mirror / code / Atom feed
* searching words in history similar to insert-last-word
@ 2013-03-14 12:06 Dominik Vogt
       [not found] ` <CAHYJk3SkuwnHAWhe_NFJpGT-VpBhO1CSOTiP-_mYzXnWb=bPnA@mail.gmail.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Dominik Vogt @ 2013-03-14 12:06 UTC (permalink / raw)
  To: zsh-users


Hi folks,

I'm looking for a way to complete the last word I'm typing on the command
line by doing a history search.  With Alt-. (insert-last-word) I can browse
through the last words of the previous lines, but I'm looking for something
more clever.  My use case is this:

I'm copying files to remote machines with scp, e.g.

  $ scp foo user@machine1.domain:
  $ scp bar baz .* user@machine2.domain:

I'd like to be able to simplify this by being able to type

  $ scp xyz user@<SHIFT-UP><SHIFT-UP>

to yield

  $ scp xyz user@machine1.domain:

When I press <SHIFT-UP> repeatedly, zsh should replace the last word on the
line with words from the history that begin with "user@".  The function
name might be something like "beginning-search-up".  Some extra features
or options would be:

1. Ignore the first word of each line but look through all other words
   on each history line.
2. (If the word that is to be completed is the first word on the line,
   only consider the first word of all history lines.)
3. Allow searching in the other direction with <SHIFT-DOWN>.

--

And as a related but seperate issue:

How can I make a function that works like insert-last-word but works in the
opposite direction (insert-next-word).  This would of course only be
usefull if I use insert-last-word first.

Ciao

Dominik ^_^  ^_^


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

* Re: searching words in history similar to insert-last-word
       [not found] ` <CAHYJk3SkuwnHAWhe_NFJpGT-VpBhO1CSOTiP-_mYzXnWb=bPnA@mail.gmail.com>
@ 2013-03-14 12:17   ` Mikael Magnusson
  0 siblings, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2013-03-14 12:17 UTC (permalink / raw)
  To: zsh-users; +Cc: Dominik Vogt

On 14 March 2013 13:06, Dominik Vogt <VOGT@de.ibm.com> wrote:
>
> Hi folks,
>
> I'm looking for a way to complete the last word I'm typing on the command
> line by doing a history search.  With Alt-. (insert-last-word) I can browse
> through the last words of the previous lines, but I'm looking for something
> more clever.  My use case is this:
>
> I'm copying files to remote machines with scp, e.g.
>
>   $ scp foo user@machine1.domain:
>   $ scp bar baz .* user@machine2.domain:
>
> I'd like to be able to simplify this by being able to type
>
>   $ scp xyz user@<SHIFT-UP><SHIFT-UP>
>
> to yield
>
>   $ scp xyz user@machine1.domain:
>
> When I press <SHIFT-UP> repeatedly, zsh should replace the last word on the
> line with words from the history that begin with "user@".  The function
> name might be something like "beginning-search-up".  Some extra features
> or options would be:
>
> 1. Ignore the first word of each line but look through all other words
>    on each history line.
> 2. (If the word that is to be completed is the first word on the line,
>    only consider the first word of all history lines.)
> 3. Allow searching in the other direction with <SHIFT-DOWN>.

alt-/ (_history-complete-older)

> And as a related but seperate issue:
>
> How can I make a function that works like insert-last-word but works in the
> opposite direction (insert-next-word).  This would of course only be
> usefull if I use insert-last-word first.

_insert_next_word () {
        zle .insert-last-word 1 -1
}
zle -N insert-next-word _insert_next_word

-- 
Mikael Magnusson


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

* Re: searching words in history similar to insert-last-word
  2013-03-14 12:32 Dominik Vogt
@ 2013-03-14 18:12 ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2013-03-14 18:12 UTC (permalink / raw)
  To: zsh-users

On Mar 14,  1:32pm, Dominik Vogt wrote:
}
} Great, that's almost exactly what I was looking for.  Is there a way to get
} rid of the duplicates though?

zstyle ':completion:history-words:*' remove-all-dups yes

You might also want

zstyle ':completion:history-words:*' sort yes


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

* searching words in history similar to insert-last-word
@ 2013-03-14 12:32 Dominik Vogt
  2013-03-14 18:12 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Dominik Vogt @ 2013-03-14 12:32 UTC (permalink / raw)
  To: zsh-users


> alt-/ (_history-complete-older)

Great, that's almost exactly what I was looking for.  Is there a way to get
rid of the duplicates though?  I get a list of matching words like this:

  user@machine1 user@machine2 user@machine1 user@machine2 ...

instead of just

  user@machine1 user@machine2

> _insert_next_word () {
> 		 zle .insert-last-word 1 -1
> }
> zle -N insert-next-word _insert_next_word

Perfect, thank you very much.  :-)

Ciao

Dominik ^_^  ^_^


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

end of thread, other threads:[~2013-03-14 18:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-14 12:06 searching words in history similar to insert-last-word Dominik Vogt
     [not found] ` <CAHYJk3SkuwnHAWhe_NFJpGT-VpBhO1CSOTiP-_mYzXnWb=bPnA@mail.gmail.com>
2013-03-14 12:17   ` Mikael Magnusson
2013-03-14 12:32 Dominik Vogt
2013-03-14 18:12 ` Bart Schaefer

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