Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Mimicking tcsh line-editing behavior
- X-seq: zsh-users 14214
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Mimicking tcsh line-editing behavior
- Date: Thu, 2 Jul 2009 21:50:39 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=kvAJ9aI7V4H73QRxOoAGOgRqqJKjBTQBeX2Q6+ejgdA=; b=UMgC9/7Pv45lkvrko4tbONKDZ90yJ9cYzv5i/aqt5y2w1iYH6kgOe8Wcr6RaYM0GfH KI9ObsucITi8LvQjraFcTRnnhKCC6ifgmuPfxArAA5BifG0DKvFl/pHxFupWnHuKqEJx YTzHSrxNa9DcXJZI+drOE8QT0lxsTPPruIa1c=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=qFhqzYCl8m9zecsl+zdDz4pN22edfCrvbIp2z2NDISN2TeSRFooyaFjbdbBnquSZD2 zJQzL7zCmsd1rEbqKo/3Ok2xom4fqIM/QO7ZMxsvL4tOFqzntAYD3K83c/67MG7RBfAG buKobT41A0FpGaNZCFBvJudnKWtXNoFyuG58M=
- In-reply-to: <198303.88532.qm@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <198303.88532.qm@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
2009/7/2 Rhyme Tan <rhymetan@xxxxxxxxxxxxxx>:
> My default shell is tcsh. In tcsh I can use alt(meta)-backspace, alt-F or
> alt-B to delete, or move forward or backward through a path.
>
> For example I type:
>
> ls /An/Example/of/a/Path/Name/
>
> To delete Path/Name/, I simply hold down the alt key and press backspace
> twice (alt-backspace x2). This will leave me with the path
> "/An/Example/of/a/". I cannot do this in zsh because pressing
> alt-backspace will delete the whole path (that is,
> "/An/Example/of/a/Path/Name/"). Is there some magic config option
> I can pass to zsh to duplicate the behavior of alt-backspace, -F, or -B) in
> tcsh?
>
> Thanks.
This was posted here some time ago (months, years, who knows?) and I
have used it since:
_my_extended_wordchars='*?_-.[]~=&;!#$%^(){}<>:@,\\';
#'
_my_extended_wordchars_space="${my_extended_wordchars} "
_my_extended_wordchars_slash="${my_extended_wordchars}/"
# is the current position \-quoted ?
function _is_quoted(){
test "${BUFFER[$CURSOR-1,CURSOR-1]}" = "\\"
}
_unquote-backward-delete-word(){
while _is_quoted
do zle .backward-kill-word
done
}
_unquote-forward-delete-word(){
while _is_quoted
do zle .kill-word
done
}
_unquote-backward-word(){
while _is_quoted
do zle .backward-word
done
}
_unquote-forward-word(){
while _is_quoted
do zle .forward-word
done
}
_backward-delete-to-space() {
local WORDCHARS=${_my_extended_wordchars_slash}
zle .backward-kill-word
_unquote-backward-delete-word
}
_backward-delete-to-/ () {
local WORDCHARS=${_my_extended_wordchars}
zle .backward-kill-word
_unquote-backward-delete-word
}
_forward-delete-to-space() {
local WORDCHARS=${_my_extended_wordchars_slash}
zle .kill-word
_unquote-forward-delete-word
}
_forward-delete-to-/ () {
local WORDCHARS=${_my_extended_wordchars}
zle .kill-word
_unquote-forward-delete-word
}
_backward-to-space() {
local WORDCHARS=${_my_extended_wordchars_slash}
zle .backward-word
_unquote-backward-word
}
_forward-to-space() {
local WORDCHARS=${_my_extended_wordchars_slash}
zle .forward-word
_unquote-forward-word
}
_backward-to-/ () {
local WORDCHARS=${_my_extended_wordchars}
zle .backward-word
_unquote-backward-word
}
_forward-to-/ () {
local WORDCHARS=${_my_extended_wordchars}
zle .forward-word
_unquote-forward-word
}
zle -N _backward-delete-to-/
zle -N _forward-delete-to-/
zle -N _backward-delete-to-space
zle -N _forward-delete-to-space
zle -N _backward-to-/
zle -N _forward-to-/
bindkey '^w' _backward-delete-to-/
bindkey '^[^w' _backward-delete-to-space
bindkey "^[^[[D" _backward-to-/
bindkey "^[^[[C" _forward-to-/
bindkey "^[^B" _backward-to-/
bindkey "^[^F" _forward-to-/
bindkey "^[^?" _backward-delete-to-/
bindkey "^[^[[3~" _forward-delete-to-/
adjust the bindings to your liking obviously. It is not perfect when
it comes across some multibyte characters i think.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author