Use terminfo key codes instead of hardcoded ones for key bindings #1355

Merged
merged 5 commits into from Mar 13, 2014

Conversation

Projects
None yet
@F30
Contributor

F30 commented Oct 14, 2012

Hardcoded key escape sequences (such as [[A for arrow-up) serve their purpose in most cases, but not in any terminal configuration. It's a better practice to query the right codes dynamically from $terminfo instead.

I expect this to become a real-world problem as soon as recent Debian and Ubuntu versions become used more widely: Those ship with a /etc/zsh/zshrc which enables "application mode", in which oh-my-zsh's key bindings partially don't work. I've written down more about that problem on my blog.

My commits migrate the key bindings to terminfo wherever possible. Please note that in order to use $terminfo, my code hast to activate the "application mode" as well and might therefore break custom hardcoded key bindings. I based my work on the documentation efforts by @kylewest from pull request #889.

@crcastle

This comment has been minimized.

Show comment
Hide comment
@crcastle

crcastle Dec 7, 2012

I just did an upgrade of oh-my-zsh, and the history-substring-search plugin broke. I fixed it by adding the following two lines to my personal zshrc (non oh-my-zsh) file.

bindkey '\eOA' history-substring-search-up
bindkey '\eOB' history-substring-search-down

I figured this out by doing Ctrl-v <up-arrow> before and after the oh-my-zsh upgrade. Before it returned ^[[A. Now it returns ^[OA.

I think this pull request is the better way to deal with this. Please merge it in!

crcastle commented Dec 7, 2012

I just did an upgrade of oh-my-zsh, and the history-substring-search plugin broke. I fixed it by adding the following two lines to my personal zshrc (non oh-my-zsh) file.

bindkey '\eOA' history-substring-search-up
bindkey '\eOB' history-substring-search-down

I figured this out by doing Ctrl-v <up-arrow> before and after the oh-my-zsh upgrade. Before it returned ^[[A. Now it returns ^[OA.

I think this pull request is the better way to deal with this. Please merge it in!

@assaflavi

This comment has been minimized.

Show comment
Hide comment
@assaflavi

assaflavi Jan 12, 2013

Thanks, F30, for this fix. I adopted your changes manually, but I hope they get merged to master soon.

Thanks, F30, for this fix. I adopted your changes manually, but I hope they get merged to master soon.

@vanhalt

This comment has been minimized.

Show comment
Hide comment
@vanhalt

vanhalt Apr 18, 2013

Tested in:

lsb_release -a
Description:    Ubuntu 12.10
Release:        12.10

zsh --version
zsh 5.0.0 (x86_64-unknown-linux-gnu)

Applied manually:

mv key-bindings.zsh key-bindings_original.zsh
wget https://raw.github.com/F30/oh-my-zsh/174c9177aa34b4c05bb5a1c6f637e6fa479a8e10/lib/key-bindings.zsh

Really dirty but did the job, please merge this :)

Thanks to @F30!

vanhalt commented Apr 18, 2013

Tested in:

lsb_release -a
Description:    Ubuntu 12.10
Release:        12.10

zsh --version
zsh 5.0.0 (x86_64-unknown-linux-gnu)

Applied manually:

mv key-bindings.zsh key-bindings_original.zsh
wget https://raw.github.com/F30/oh-my-zsh/174c9177aa34b4c05bb5a1c6f637e6fa479a8e10/lib/key-bindings.zsh

Really dirty but did the job, please merge this :)

Thanks to @F30!

@carlosagp

This comment has been minimized.

Show comment
Hide comment
@carlosagp

carlosagp Jul 6, 2013

+1 This is a good patch. Please merge!

+1 This is a good patch. Please merge!

@Taluu

This comment has been minimized.

Show comment
Hide comment
@Taluu

Taluu Jan 22, 2014

This did the trick for me. :)

Taluu commented Jan 22, 2014

This did the trick for me. :)

@thisch

This comment has been minimized.

Show comment
Hide comment
@thisch

thisch Jan 22, 2014

Please merge

thisch commented Jan 22, 2014

Please merge

robbyrussell added a commit that referenced this pull request Mar 13, 2014

Merge pull request #1355 from F30/key-bindings
Use terminfo key codes instead of hardcoded ones for key bindings

@robbyrussell robbyrussell merged commit 7adf66f into robbyrussell:master Mar 13, 2014

@thuandt

This comment has been minimized.

Show comment
Hide comment
@thuandt

thuandt Mar 13, 2014

Contributor

After update oh-my-zsh with this patch, plugin history-substring-search don't work

Contributor

thuandt commented Mar 13, 2014

After update oh-my-zsh with this patch, plugin history-substring-search don't work

@mcornella

This comment has been minimized.

Show comment
Hide comment
@mcornella

mcornella Mar 13, 2014

Collaborator

Hi @thuandt, I recommend you open a new issue to have a better chance of being seen. Within the new issue, make sure to add your system version (lsb_release -a) and zsh version (zsh --version)

Collaborator

mcornella commented Mar 13, 2014

Hi @thuandt, I recommend you open a new issue to have a better chance of being seen. Within the new issue, make sure to add your system version (lsb_release -a) and zsh version (zsh --version)

@pierrre

This comment has been minimized.

Show comment
Hide comment
@pierrre

pierrre Mar 14, 2014

+1 history search with up/down arrow key is broken...

pierrre commented Mar 14, 2014

+1 history search with up/down arrow key is broken...

@mgol

This comment has been minimized.

Show comment
Hide comment
@mgol

mgol Mar 18, 2014

This introduced issue #2628.

mgol commented on ff0cafa Mar 18, 2014

This introduced issue #2628.

This comment has been minimized.

Show comment
Hide comment
@eddiemonge

eddiemonge Apr 21, 2014

Contributor

and #2654

Contributor

eddiemonge replied Apr 21, 2014

and #2654

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment