Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

Thanks!

share|improve this question
    
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

2 Answers 2

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
share|improve this answer
    
Thanks for your info, but my $TERM is always set to xterm, on all the machines –  CodeNoob 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.

See:

:help 'nocompatible'

(With the single quotes.)

share|improve this answer
    
Thanks for your reply. I tried to switch back and forth between the compatibility mode, it doesn;t work. :) –  CodeNoob Jul 19 '12 at 19:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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