-
-
Notifications
You must be signed in to change notification settings - Fork 26k
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
Ditch smkx in favor of custom bindkey extension #5113
Conversation
Thanks for this Andrew, hopefully I'll have it checked out in less than a week. I agree on the failed experiment sentiment, I think this is the only way forward. |
The Terminfo What I don't get is why it works for you, perhaps you have overwritten My
|
Ah, yes: that will need to be changed to use I didn't notice it because I have some additional key bindings set in my |
Okay, I've amended the PR to handle |
The If only one of these should work, I think My suggestion is to use |
Good catch. I think it'll be more readable if we stick to a canonical ordering. (Alternately, the I've switched it to using your suggested canonical ordering. The |
Ok, this appeared to fix #5228, which I've added to the list of fixes. I'll see if we can accelerate the testing of this PR so we can merge it right away. |
FYI I've switched to this PR for now, as this solves keybinding problems with the home/end/ctrl+left and ctrl+right keys in IntelliJ IDEA 2016.2.4 (on Ubuntu 16.04). I see no problem at this moment, but will log any issue here if I find one. Let me know if this is not the proper place for "testers". |
@snussbaumer yes this is the proper place, thanks for commenting. Did you have to do anything extra after applying this PR, i.e. delete some |
I could remove the following bindkey :
but I still need :
Note : these |
Another note : in IntelliJ terminal showkey gives me the following bindings :
Whereas when I'm in GNU terminal I get :
Luckily my changes in zshrc seem to be ok in both environments ... but still this is quite confusing ok I get it, it looks as if you can have mulitple bindings for the same command, that's why it's working :
|
Good to hear. That sounds like IntelliJ is behaving oddly for Ctrl-modified arrow keys. That Someone should report this as a bug upstream to IntelliJ. |
For the
|
I don't think that will work. The I suspect this is a bug in the IntelliJ terminal plugin. It looks like it's naively inserting a |
Oh right, my mistake, I meant the other two sequences. |
Curious why this is still open and unmerged? Is it because there are still more tests needed before feeling it's safe to merge? to this date, even using master, vi-mode is still broken in numerous cases, as is safe-paste. |
@mcornella Do you think this is close to merge-able? |
Also from my perspective: why is this problem still not solved? For a terminal extension that is used by so many people (87,000 stars) it is embarrassing if simple things like crtl-left or the Numpad don't work. Please fix it! @robobenklein @mcornella @apjanke |
We could really use some testers on this. Thanks in advance! |
I have merged this pull request into my fork and have not encountered any problems with it. On these systems and platforms: |
The safe-paste plugin apparently breaks up-arrow / down-arrow fuzzy search for reasons... see ohmyzsh/ohmyzsh#5113 once that is merged the problem should be fixed.
Could you please upstream this, by getting rid of the conflicts? If so we would then be able to continue our reviews on it. Thank You! |
Rebased and resolved conflicts; I think I got it right. |
@apjanke Thank you. @mcornella Do we want to proceed with a PR review? |
I've encountered a bug with this PR: when I type a command and go up to search in my history all commands starting with the first word appear (not necessarily the full command). |
Hmmmm... I can't reproduce your issue. When I check out my Maybe you've got some other autocompletion configuration stuff going on? Are you all rebased on |
@apjanke I tried again and it didn't happen anymore ! |
Okay, good to hear! |
What is the status on this PR? |
Motivation
More than 2 years ago, Oh My Zsh merged the Pull Request #1355, which introduced a fix to be able to use terminfo sequences to specify key codes to
bindkey
, with the intention to make it standard for everyone and not having to change bindkey sequences all the time.That experiment failed, and it's been obviously clear for quite a while. Since then lots of issues have popped up where certain combinations of keys didn't work (see list of Fixes below), and the culprit of that is that terminfo databases are not maintained all that well and there is not consistent support among Terminal Emulators.
This is why we're choosing to drop that experiment, and use a custom wrapper around bindkey named
omz_bindkey
were you'll be able to choose whichever modifier keys you want ─ CTRL, ALT, SHIFT, META ─ instead of having to use an obscure character sequence like'^[[OH'
.Here's where you come into play: since this is a big change, we need a broad number of users to test in their respective configurations, with as many Terminal Emulators as we can, before we can safely merge this PR knowing that there won't be many users affected.
Thanks for taking the time to read this; in this GitHub guide you'll find how you can check out this PR locally. After that, restart your terminal or run
exec zsh
to reload Oh My Zsh.Please report back if there are any keyboard shortcuts broken in your system with the following information:
echo $ZSH_VERSION
.echo $TERM
.bindkey
configuration: runbindkey
and post its output.That is all. Thanks again for participating in this! ─ @mcornella
Description
I think it's time to abandon
smkx
/rmkx
and stick with "local" keypad mode, even if it requires us to hardcode a few character sequences instead of using terminfo for everything. This PR does so, adding anomz_bindkey
function that allows us to still use terminfo capability codes in key bindings, and supports cursor keys with modifiers. This should fix a whole slew of these recurring cursor-key terminal issues.Fixes #4916 – Num Pad can't input
Fixes #4872 – Home and End not working in MobaXterm
Fixes #4784 – Home and End not working in PhpStorm terminal in Mac OS/X
Fixes #3757 – Home/End broken in PuTTY
Fixes #3733 – Home/End broken in CentOS
Fixes #3495 – Home/End broken in CentOS
Fixes #3061 – Home/End broken in Ubuntu
Probably fixes #2750 – Cursor key bindings broken in urxvt on openSUSE – or at least makes it moot
Fixes #2735 – history-substring-search key bindings broken after terminfo changeover
Fixes #2698 – Home/End broken in gnome-terminal
Fixes #2654 – Num keypad broken on OS X
Fixes #2369 – Change to option-arrow behavior on OS X
Fixes #5149 – Plugin 'safe-paste' messes with 'history-substring-search'
Fixes #5228 – Application mode not working on xterm.js
Fixes #5237 - Safe-paste plugin breaks Home/End
Avoids xtermjs/xterm.js#151 - zsh / oh-my-zsh - no scroll
...and all those other issues about Home/End or the numeric keypad.
Discussion
Switching to use smkx/rmkx application mode and terminfo for portability was a good idea: you're supposed to use portability libraries for stuff like this. But I think it's time to call it a failed experiment. Not because the implementation in OMZ was bad, but because terminfo and the various terminal programs out there don't have sufficient support for it.
I dug pretty deep in to this issue, and I think that the smkx/rmkx+terminfo solution cannot be made to work for everyone. And you'll continue to see issues reported for it. But local mode with a few hardcoded sequences can work.
The smkx/rmkx approach is defeated by a few factors:
xterm
, which is what most people use for their$TERM
, even if they're really running a different programUsing smkx/rmkx is also complicated because:
bash
only supports local mode, so bash cursor code can't be used under [sr]mkxzle-line-init
andzle-line-finish
hooks, which conflicts with anything else that wants to use them (including some OMZ plugins).zle-line-init/finish hooks
As part of this PR's changes, Oh My Zsh completely takes over the
zle-line-init
andzle-line-finish
hooks, replacing them with functions that provide support for multiple hook functions to be registered. This is done for two independent reasons. Primarily, it's to clobber and remove any zle-line-init/finish hooks installed by zsh configuration files supplied by the system. Some Linux distributions define hooks which do the [sr]mkx thing, and we need to make sure that doesn't happen. Secondly, it allows for multiple OMZ plugins to install line-init/finish hooks without conflicting with each other.As part of this, we're essentially having OMZ declare zle-line-init/finish to be completely its territory. I think this is okay.
Implementation
The terminfo-based key binding code was a lot easier to read, because it used mnemonic terminfo capability codes instead of literal terminal control sequences. So this PR adds an
omz_bindkey
extension on top ofbindkey
that allows you to still use those codes. (It also adds logging support, which would make diagnosing key binding issues a lot easier, because you could see which plugins or user code is doing which binding.) I think this makes the key binding code a lot more readable, both as it is, and in the diffs for future PRs.The
omz_bindkey
layer keeps a supplemental little database of character sequences based on xterm's local mode behavior (which is not in terminfo), and uses those for cursor keys. It also includes a couple hacks for specific known misbehaving or variant terminal programs. And it has support for binding modifier-key (alt/ctrl/shift) cursor keys, which terminfo doesn't itself provide.Future considerations
If you like this approach and merge it, I'll follow it up with a PR for multiple keymap support in the key bindings, which will take care of the issues caused by flipping between the
emacs
andvi
keymaps during the OMZ startup sequence.