Skip to content

Instantly share code, notes, and snippets.

@dylanwh
Last active April 30, 2021 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanwh/791c0b49f407f7dd7127b0d511627e4d to your computer and use it in GitHub Desktop.
Save dylanwh/791c0b49f407f7dd7127b0d511627e4d to your computer and use it in GitHub Desktop.
fixing home/end/pageup/pagedown in terminal programs

Problem

Your Home/End/PageUp/PageDown keys are not working consistently in terminal programs like vim or zsh.

Debugging

First, run cat -vt >/dev/null and type Home, followed by enter. You should see something like below

cat -vt >/dev/null
^[[H

Your output might not look like that, but what you're going to do is check what the keyboard produces in the specific terminal and compare against the terminfo description of your current terminal setting. In the terminfo description ^[ is replaced with \E.

infocmp|fgrep '\E[H,'
el1=\E[1K, flash=\E[?5h$<100/>\E[?5l, home=\E[H,

So if you see output like the above (home=\E[H), that means terminfo is correct. However you probably won't see that because if it was correct you probably wouldn't be here...

Fixing the problem (several ways)

In the past I brute-forced fixed this in zsh, by using the bind-key function and just binding the correct commands. my old zshrc showing how to bind home/end/etc

I never had to do this with vim because vim presumably vim has overrides for broken terminfos..

however, the best fix is downloading this file as ~/.terminfo/x/xterm-256color and using this zsh script that uses terminfo to setup zsh bindkeys

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