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

MobaXTerm "xterm" terminal - END, HOME, DEL keys not working #4872

Closed
Lopson opened this issue Feb 23, 2016 · 26 comments
Closed

MobaXTerm "xterm" terminal - END, HOME, DEL keys not working #4872

Lopson opened this issue Feb 23, 2016 · 26 comments
Labels
Resolution: not our issue Issue or pull request not related to Oh My Zsh Support Request for support Topic: bindkey Pull Request or issue regarding keyboard shortcuts

Comments

@Lopson
Copy link

Lopson commented Feb 23, 2016

I don't know if putting this up on this project is the right way to go, but when I searched for tickets in this git, I saw similar ones, so here goes.

I have a CentOS 7.2.1511 machine, with ZSH 5.0.2 installed. I have the latest version of oh-my-zsh installed, along with the plugin ZSH-Syntax-Highlighting.

To connect to this machine, I use MobaXTerm (latest version). I connect to the CentOS machine through SSH and present the terminal as being of the "xterm" type (the default option for this SSH client).

The standard HOME, END, DEL, etc keys don't work out-of-the-box. I don't know how to make a Terminfo file for this case, and it seems like I shouldn't be needing to come up with a new Terminfo in the first place, seeing as MobaXTerm truly is an xterm terminal.

As such, I'd like to hear from you on this matter: is there some kind of known bug with this specific ZSH version that impedes MobaXTerm from working as intented?

Thanks for your time.

@apjanke
Copy link
Contributor

apjanke commented Feb 24, 2016

This is an ongoing issue with key bindings and terminfo in OMZ. #3061 is probably closest to your issue, and has some detailed information. You can see various other Home/End key binding issues in the list in #4344.

Thought we had Home/End cleared up for most terminals. Check that the character sequences MobaXTerm is sending for Home and End match those in the xterm terminfo entry.

@apjanke
Copy link
Contributor

apjanke commented Feb 24, 2016

I grabbed MobaXterm and tried it out. It looks like in application cursor mode, it's sending the character sequences for the VT220 editing keypad Home/End keys (^[[1~ and ^[[4~) instead of the PC style Home/End keys like xterm does (^[OH and ^[OF). So its behavior doesn't match the xterm terminfo entry, at least for those keys. OMZ currently sets up bindings that rely on the terminfo entry.

Eventually OMZ may be able to handle this automatically, but in the mean time you'll have to configure a workaround.

If you can configure MobaXterm to send the normal xterm sequences, that should fix it.

PuTTY does the same thing in one of its configurations. Have a look at #3757, which is specifically about PuTTY. As a workaround, you could add this in your ~/.zshrc file.

bindkey '^[[1~' beginning-of-line
bindkey '^[[4~' end-of-line

@apjanke
Copy link
Contributor

apjanke commented Feb 24, 2016

And looking at the Help > About MobaXterm dialog, it seems like that may actually be an embedded PuTTY that they're using for the SSH client. Could be why the behavior is similar.

mobaxterm - about - annotated

@Lopson
Copy link
Author

Lopson commented Feb 24, 2016

MobaXterm is based on PuTTY, somehow. From their documentation page:

MobaXterm features a great terminal emulator based on the efficient PuTTY program (by Simon Tatham).

I've sent them an e-mail a while back asking them about this specific matter, but I haven't heard back from them yet. I've taken a look at the files the program generates in its configuration folder, but I haven't found a way of changing the characters it sends when I press the aforementioned keys.

In its configuration folder, I managed to snag two relevant files. One of them is a terminfo file; another is a inputrc file. Hopefully, they'll be useful for something!

[https://drive.google.com/file/d/0Bwi2temj01hfaEdCNTZ3T24xWFU/view?usp=sharing](MobaXterm Files.zip)

@apjanke
Copy link
Contributor

apjanke commented Feb 24, 2016

Ah! In that case, you can try setting $TERM to putty instead of xterm. Many systems have a putty terminfo entry which has Home/End entries that match putty's default behavior.

$ infocmp -1 putty  | grep 'khome\|end'
    kend=\E[4~,
    khome=\E[1~,

@Lopson
Copy link
Author

Lopson commented Feb 25, 2016

While my system does have a proper terminfo entry for putty-type terminals, setting the terminal type to putty doesn't set the correct keybindings for HOME and END. However, the DELETE key is set properly.

Here's showkey -a's output when pressing HOME and END by this order in MobaXterm:

» |root@Base 8:34:44| /root showkey -a
Press any keys - Ctrl-D will terminate this program

^[[H     27 0033 0x1b
         91 0133 0x5b
         72 0110 0x48
^[[F     27 0033 0x1b
         91 0133 0x5b
         70 0106 0x46

@apjanke
Copy link
Contributor

apjanke commented Feb 25, 2016

There's a catch here: OMZ switches the terminal into "application keypad" mode when the ZLE command line editor is active, using terminfo's smkx. (This is so it can use portable terminfo-based key bindings.) This causes the cursor keys (up/down/left/right/home/end) to send different character sequences. It's switched back in to normal/local mode after line editing ends. So the key sequences that showkey is seeing for home and end may not (and usually shouldn't) be the same ones that the zsh command line editor is seeing. When I tried out MobaXterm, it respected keypad mode switching, and gave ^[[1~/^[[4~ in application mode. Could you test that too?

Instead of showkey, try using Ctrl-v ("verbatim") to see what sequences the keys are sending, without leaving the command line editor. Ctrl-v followed by another keystroke will just add the literal character sequence to the command line buffer, even if it's an escape or other control sequence.

Could also be that your setup is leaving the terminal in local cursor mode.

Maybe MobaXterm has their own documentation on configuring their terminal, though I didn't see much in my brief poking around at it.

(I wonder what version and configuration of Putty they're using. When I was doing that testing, I tested a few Putty configurations, and none of them gave ^[[H/^[[F; the closest was ^[[H/^[Ow. And it didn't respect keypad mode switches.)

@Lopson
Copy link
Author

Lopson commented Feb 26, 2016

Just did the CTRL+V test on the same CentOS 7 machine I've been using thus far; got, yet again, ^[[H for Home and ^[[F for End. Again, much like in my last post, I set the terminal type to putty.

If I use the default xterm terminal type, I get ^[[1~ for Home, ^[[4~ for End, and ^[[3~ for Delete.

I don't really understand this smkx business, so I'm not entirely sure how to help you any further. If more data is required in order to help you guys out, just say what needs to be done and I'll get on it!

@apjanke
Copy link
Contributor

apjanke commented Feb 26, 2016

Interesting.

Setting $TERM to whatever shouldn't affect this test – that should just change how programs interpret the character sequences, not what your terminal sends.

This makes me think that the "terminal type" setting in MobaXterm is affecting not just the $TERM it reports, but PuTTY's character sequence settings. Which makes sense: PuTTY can be configured in terms of what its cursor keys send to the server.

putty cursor keys annotated

And in stock PuTTY, this is configured independent of the $TERM string that PuTTY defines for the server. This makes me think that maybe MobaXterm is conflating these things and presenting a simplified configuration sheet.

I dunno what to suggest you do right now. This really ought to be Not Your Problem.

To OMZ contributors: this looks to me like more support for ditching [sr]mkx and going with hacking in terminal-specific codes. Local-mode behavior is so much more regular.

I don't really understand this smkx business, ...

Yeah, no reason you should. This is a bunch of historical stuff going all the way back to the sixties and the particular terminals that were built then. Sorry it's making your (and my) life harder.

@fabceolin
Copy link

Try to set terminal type = byobu in xmobaterm

@hiephm
Copy link

hiephm commented May 21, 2017

Suggestion from @Lopson works for me. After using showkey -a and know the key code, I just put these lines to .zshrc and it works perfect:

# Fix MobaXterm Home/End key with ZSH
bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line

Edit: $TERM need to be linux or putty since xterm will not work.

@tldrblt
Copy link

tldrblt commented May 21, 2017

I tried the fix from @hiephm (my showkey -a results are the same as his), but:

With export TERM=putty, my Home and End keys still don't work.
With export TERM=linux, my Home and End keys worked, but after every command I get the following error messages:

zle-line-finish:echoti:1: no such terminfo capability: rmkx
zle-line-init:echoti:1: no such terminfo capability: smkx

I am guessing the errors are talking about my OMZ prompt, which is:

PROMPT="


%{$bg[white]$terminfo[bold]$fg[black]%} %D{%F %T %Z} %{$reset_color%} [%*]
%{$bg[white]$terminfo[bold]$fg[black]%}# \
%(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%n) \
@ \
%m %{$reset_color%} \
%{$fg[white]%}in \
%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\
${hg_info}\
${git_info}\
 \
 $exit_code
%{$terminfo[bold]$fg[red]%}$ %{$reset_color%}"

So I either need to

  1. Get Home and End keys working with export TERM=putty (How?), -or-
  2. I need to edit my prompt so that it works with export TERM=linux (What needs to change?), -or-
  3. I need to find a different value for $TERM that will work with Home and End keys AND custom prompt without errors (What are some other valid values for $TERM that I can try?).

Anybody have suggestions for these? I also tried export TERM=vt100, but results was same as export TERM=putty.

@goldeneye977
Copy link

I fixed the issue by using an AutoHotkey script. I wrote a small script that if the active window is MobaXTerm's, change the Home/End keys to "CTRL+A/CTRL+E" respectively. Here's the script if anyone wants to try it out:

#If WinActive("ahk_class TMobaXtermForm")
{
Home::
#UseHook Off
Send ^A
#UseHook
return

End::
#UseHook Off
Send ^E
#UseHook
return
}
#If

@tldrblt
Copy link

tldrblt commented Aug 25, 2017

Thanks @goldeneye977 . Your AutoHotkey script works for me as well. My time in the terminal just got a little bit nicer thanks to you. Cheers.

@goldeneye977
Copy link

BTW @tldrblt, the script has a minor issue. If u detach the MobaXTerm window, it's won't work there because the window's ahk_class changes. This can be fixed by using "ahk_exe MobaXterm.exe" instead. Hope that helps!

@rb1980
Copy link

rb1980 commented Oct 13, 2017

Wow @goldeneye977 I literally spent hours trying to get ALL the other suggestions floating around out there working till I came across your AutoHotKey script. Since I was already using AHK, literally a copy/paste/reload, and 10 seconds later, I am a happy camper. +1 +1 +1

@mcornella mcornella added the Topic: bindkey Pull Request or issue regarding keyboard shortcuts label Apr 8, 2019
@sirhaplo
Copy link

Fix MobaXterm Home/End key with ZSH

bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line

Suggestion from @Lopson works for me. After using showkey -a and know the key code, I just put these lines to .zshrc and it works perfect:

# Fix MobaXterm Home/End key with ZSH
bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line

Edit: $TERM need to be linux or putty since xterm will not work.

I used this solution, but i wrote manually linux in the terminal select box of Mobaxterm

@rebeccasf
Copy link

Fix MobaXterm Home/End key with ZSH

bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line

Suggestion from @Lopson works for me. After using showkey -a and know the key code, I just put these lines to .zshrc and it works perfect:

# Fix MobaXterm Home/End key with ZSH
bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line

Edit: $TERM need to be linux or putty since xterm will not work.

I used this solution, but i wrote manually linux in the terminal select box of Mobaxterm

This works!

@rupingmo
Copy link

rupingmo commented Feb 4, 2020

From MobaXterm window, click "Settings", select "X11", and then deselect "Unix-compatible keyboard". It works for this way.

@pytimer
Copy link

pytimer commented Jul 6, 2020

Suggestion from @Lopson works for me. After using showkey -a and know the key code, I just put these lines to .zshrc and it works perfect:

# Fix MobaXterm Home/End key with ZSH
bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line

Edit: $TERM need to be linux or putty since xterm will not work.

It works for me!

@jbroq
Copy link

jbroq commented Aug 10, 2020

Fix MobaXterm Home/End key with ZSH

bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line

Suggestion from @Lopson works for me. After using showkey -a and know the key code, I just put these lines to .zshrc and it works perfect:

# Fix MobaXterm Home/End key with ZSH
bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line

Edit: $TERM need to be linux or putty since xterm will not work.

I used this solution, but i wrote manually linux in the terminal select box of Mobaxterm

I works for me too. Thanks

@1Mark
Copy link

1Mark commented Apr 6, 2022

Any chance getting a fix for this?

@1Mark
Copy link

1Mark commented Apr 6, 2022

The following works with xterm-256color

bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line

@miku86
Copy link

miku86 commented Aug 27, 2022

Just to summarize this for people like me, who needed 2h of internet search to fix this with xterm and zsh:

  1. Open a terminal and run showkey -a
  2. Hit the key, e.g. Home and look for code like ^[[H
  3. Add a bindkey instruction for the key to your .zshrc file
  4. Do step 2 and 3 for each key you want to change

My .zshrc file now looks like this:

bindkey '^[[H' beginning-of-line # Home
bindkey '^[[F' end-of-line # End
bindkey '^[[2~' overwrite-mode # Insert
bindkey '^[[3~' delete-char # Delete
bindkey '^?' backward-delete-char # Backspace

The comment at the end of each line (starting with a #) is just that I know which key it is for.

@Mr-Saikiran
Copy link

Just to summarize this for people like me, who needed 2h of internet search to fix this with xterm and zsh:

  1. Open a terminal and run showkey -a
  2. Hit the key, e.g. Home and look for code like ^[[H
  3. Add a bindkey instruction for the key to your .zshrc file
  4. Do step 2 and 3 for each key you want to change

My .zshrc file now looks like this:

bindkey '^[[H' beginning-of-line # Home
bindkey '^[[F' end-of-line # End
bindkey '^[[2~' overwrite-mode # Insert
bindkey '^[[3~' delete-char # Delete
bindkey '^?' backward-delete-char # Backspace

The comment at the end of each line (starting with a #) is just that I know which key it is for.

This is the best solution so far !!

@carlosala
Copy link
Member

Let's close then, thanks!☺️

@carlosala carlosala added Resolution: not our issue Issue or pull request not related to Oh My Zsh Support Request for support labels Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: not our issue Issue or pull request not related to Oh My Zsh Support Request for support Topic: bindkey Pull Request or issue regarding keyboard shortcuts
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.