Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: swapping keys
- X-seq: zsh-users 9947
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: swapping keys
- Date: Mon, 20 Feb 2006 14:50:41 +0000
- In-reply-to: <20060220141907.GA3663@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <Xns976FBAFEAC071zzappergmailcom@xxxxxxxxxxx> <EXCHANGE03bJjyve2q70000ee73@xxxxxxxxxxxxxxxxxx> <Xns97708723BE304zzappergmailcom@xxxxxxxxxxx> <20060220141907.GA3663@xxxxxxxxxx>
Francisco Borges wrote:
> One possible solution is to switch keys like "`~" and "1!" (I have to
> confess I have only swapped "`~").
>
> Since I am at it... Is it possible to swap keys inside zsh?
Yes, it's fairly straightforward. As written it doesn't work for
multibyte characters (e.g. you can't swap with a Euro or Yen or Pound
Sterling in multibyte mode). That wouldn't be too hard to fix (but it's
not as simple as just removing the test: you need a loop over bytes in
the argument).
# start
# swapkeys X Y
# swap keys X and Y so typing X gives Y and vice versa
# swapkeys -d X Y
# completely remove a previous swapping
emulate -L zsh
setopt cbases
integer delete i
local key hexkey
if [[ $1 = -d ]]; then
delete=1
shift
fi
if [[ $# -ne 2 || ${#1} -ne 1 || ${#2} -ne 1 ]]; then
print "Usage: $0 [-d] key1 key2" >&2
return 1
fi
for (( i = 1; i <= 2; i++ )); do
key=$argv[i]
hexkey=$(( [#16] #key ))
if (( delete )); then
zle -D insert-key-$hexkey
bindkey $key self-insert
else
eval "insert-key-$hexkey () { LBUFFER+=\$'\\x${hexkey##0x}'; }"
zle -N insert-key-$hexkey
bindkey ${argv[3-i]} insert-key-$hexkey
fi
done
# end
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
Messages sorted by:
Reverse Date,
Date,
Thread,
Author