Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: bindkey and widgets



On Mar 21,  3:31pm, David ( Text in unknown character set ISO-8859-15  wrote:
} 
} It is possible to map the "Ctrl+RePag" combination using bindkey?

Only if your terminal or emulator sends a different escape sequence for
the RePag key when "modifier" keys like shift/ctrl/meta/alt are pressed.

} '^\e[5~' and '\C-\e[5~'

No.  \e[5~ is the four-character sequence (escape left-bracket five tilde)
that is sent when the unmodified RePag key is pressed.  For function keys
that send multi-character sequences, pressing the control key often has
no effect, but if it has any effect at all it will be to cause another,
different multi-character sequence to be sent.

So you need to find out what that sequence is.  The easiest way may be
to type Ctrl+v (which usually means "quote next character") and then
Ctrl+RePag and see what appears.  If it looks like ^[[5~ (^[ is another
way to write \e), then your keyboard and/or terminal emulator does not
distinguish the ctrl modifier for function keys.  If it looks different,
then that is the sequence you use for bindkey.

It may be possible to program your terminal emulator to recognize ctrl
with function keys, but that's beyond what I'm prepared to explain here.

} On the other hand, how can i map one action with two widgets?. When
} the Control-K combination is pressed, i want two widgets to be executed,
} namely kill-line and end-of-history.

Creating a widget is probably the best way because it doesn't depend on
any other bindings.  However, you can use "bindkey -s".

First, assuming Ctrl+k is presently bound to kill-line, you have to make
a new binding for kill-line.  Escape left-curly-bracket is an unlikely
combination and not usually bound, so:

    bindkey '\e{' kill-line

Then you need a binding for end-of-history, which isn't attached to a key
by default.  I'll choose escape right-curly-bracket for this example:

    bindkey '\e}' end-of-history

Finally, rebind Ctrl+k with:

    bindkey -s '\C-k' '\e{\e}'

The widget, on the other hand, would look like this:

    kill-line-and-end-history () {
      zle .kill-line && zle .end-of-history
    }
    zle -N kill-line kill-line-and-end-history

That actually renames kill-line to your new widget, so all bindings for
kill-line now include jumping to the end of the history.  If you want to
change Ctrl+k only, use:

    zle -N kill-line-and-end-history
    bindkey '\C-k' kill-line-and-end-history


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



Messages sorted by: Reverse Date, Date, Thread, Author