Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind Ctrl+Left to backward-word (and Ctrl+Right to forward-word) #563

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions modules/editor/init.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ zmodload zsh/terminfo
typeset -gA key_info
key_info=(
'Control' '\C-'
'ControlLeft' '\e[1;5D \e[5D \e\e[D' # sequences from Debian's inputrc
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bind only one sequence, not three of them, because it makes the use of this array inconsistent. Find out $TERM for each then set key_info['ControlLeft']='foo'.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And how do you propose I do that? There are various accounts for correct xterm values — somebody here says their xterm works with ;5D, my xterm works with \e[1;5D if I let zsh parse my .zshrc and with ;5D if I run zsh --no-rcs.... I don't think these can be reliably inferred from $TERM, I though we were trusting Debian with this...

And what do you mean by inconsistent? Yes, it has several possible values, all of which apply, obviously.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Konsole set $TERMINAL_PROGRAM?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tried konsole, but none of my other terminal programs sets it. Does this help?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean by inconsistent is that the array is expected to be used as $key_info[ControlLeft] not ${(s: :)key_info[ControlLeft]}.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but there are three possible values. That's why I asked how I should name them. ControlLeft1, ControlLeft2, ControlLeft3 ? And how then do I conditionally add the rxvt ControlLeft4? And do I check for each one if it's set before applying bindkey to it?
What public-facing interface precisely are you maintaining backwards-compatibility with by enforcing this? I understand you don't want it all hacked together, but I don't think I can imagine an equally-elegant way of taming this better. So please advise. :-)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no good answer.

'ControlRight' '\e[1;5C \e[5C \e\e[C'
'Escape' '\e'
'Meta' '\M-'
'Backspace' "^?"
Expand Down Expand Up @@ -57,6 +59,12 @@ key_info=(
'BackTab' "$terminfo[kcbt]"
)

# additionally from Debian's inputrc
if [[ "$TERM" = *rxvt* ]]; then
key_info[ControlLeft]+=' \eOd'
key_info[ControlRight]+=' \eOc'
fi

# Set empty $key_info values to an invalid UTF-8 sequence to induce silent
# bindkey failure.
for key in "${(k)key_info[@]}"; do
Expand Down Expand Up @@ -206,10 +214,12 @@ bindkey -d
# Emacs Key Bindings
#

for key ("$key_info[Escape]"{B,b}) bindkey -M emacs "$key" emacs-backward-word
for key ("$key_info[Escape]"{F,f}) bindkey -M emacs "$key" emacs-forward-word
bindkey -M emacs "$key_info[Escape]$key_info[Left]" emacs-backward-word
bindkey -M emacs "$key_info[Escape]$key_info[Right]" emacs-forward-word
for key ("${(s: :)key_info[ControlLeft]}" \
"$key_info[Escape]"{B,b} "$key_info[Escape]$key_info[Left]")
bindkey -M emacs "$key" emacs-backward-word
for key ("${(s: :)key_info[ControlRight]}" \
"$key_info[Escape]"{F,f} "$key_info[Escape]$key_info[Right]")
bindkey -M emacs "$key" emacs-forward-word

# Kill to the beginning of the line.
for key in "$key_info[Escape]"{K,k}
Expand Down