On some Linux machines, when I use vim, I can use PageDown, PageUp, Home, End button nicely without any troubles. However on some other machines, these buttons give me funky characters.

Why is that, and what can I do?


  • It looks like we need more information. What version of Vim do you have on the various machines? Are there different Vim configurations on the different machines? Do all the machines have the TERM environmental variable correctly set? – Heptite Jul 27 '12 at 2:58

I assume that you are running vim in a terminal rather than the GUI version, gvim.

Different terminals send different characters or sequences of characters to the applications running in them when the user types a motion key such as PageDown. To determine the set of characters or character sequences that the current terminal is sending to represent those keys, Vim consults the terminfo database. It uses the TERM environment variable to determine the type of the current terminal, then accesses the terminfo definitions of those keys used by that terminal.

If the key definitions for the current value of TERM match the capabilities of your current terminal, everything works fine. If the value of TERM is incorrect for your terminal, or if the terminfo database is incomplete or missing, Vim doesn't know how to interpret the characters or character sequences sent by your terminal so it just inserts the characters into your text or interprets them as Vim commands.

The most likely cause of the problem is that TERM is not set correctly for the terminal you are using. The most straightforward fix is to find out what kind of terminal you are using, find the terminfo name for it in /usr/share/terminfo or /usr/lib/terminfo, and put a line like this in your ~/.bashrc:

export TERM=thetermifoname

For example,

export TERM=xterm
  • Thanks for your info, but my $TERM is always set to xterm, on all the machines – Vendetta Jul 19 '12 at 20:01

My first guess is that on some Linux machines, you're running in "nocompatible" mode which enables a lot of extra Vim features including the arrow keys and such, but the ones where the keys don't work you're not.

Vim automatically goes into "nocompatible" mode when you have a ~/.vimrc, but some distributions install a system vimrc that sets the 'nocompatible' option, even without a ~/.vimrc.


:help 'nocompatible'

(With the single quotes.)

  • Thanks for your reply. I tried to switch back and forth between the compatibility mode, it doesn;t work. :) – Vendetta Jul 19 '12 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.