Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I open a document using vi or vim, I am unable to navigate the page using Page Up and Page Down keys. On pressing these keys, vim seems to behave in abnormal maaner, and changes the case of character beneath the cursor. It then takes few seconds to come back again in insert mode.

Please let me know, how to map these keys, so that on pressing them I can scroll through pages smoothly just like Ctrl+ (f / b / u / d ).


Machine and Vim info

$ cat /etc/*-release  
Red Hat Enterprise Linux Server release 5.5 (Tikanga)

$ vim --version
VIM - Vi IMproved 7.0 (2006 May 7, compiled Jun 12 2009 07:08:36)


I am using Putty to connect to this machine.

share|improve this question
Are you using vim on Windows or on Linux (or something else), are you using a terminal emulator (such as Putty)? X11 or character mode? – RedGrittyBrick Sep 27 '12 at 10:25
I have this problem with Cygwin + mintty + vim. I don't fully understand the solution but the post below will hopefully steer me in the right direction. – Sridhar-Sarnobat Feb 20 '14 at 0:33


I am using Putty to connect to this machine

Then I guessed correctly and my answer below probably applies.

Original answer:

There's not enough information in your question to be certain of your problem, whilst we are waiting let me provide the audience with a little story:

The Terminal Emulator and the Editor

If you access a Linux computer using an xterm emulator such as Putty, your PgUp key sends four characters Escape [ 5 ~ to the Linux system.

The Linux system processes this and then passes any unactioned keystrokes to the application.

The application, vim, uses a system library (I believe) to translate character sequences back into "keys" based on the value of the environment variable TERM and the corresponding entry in terminfo

If terminfo doesn't define PgUp (or any other key) as Escape [ 5 ~, Vim will (probably) process the four characters individually.

"Many cursor key codes start with an Esc. Vim must find out if this is a single hit of the Esc key or the start of a cursor key sequence. It waits for a next character to arrive. If it does not arrive within one second a single Esc is assumed." So vim waits a bit to see if Esc is you wanting to exit insert mode.

[ and 5 are valid Vim commands. But maybe Vim sees the Esc as signalling the start of an escape sequence it doesn't recognize - it has to guess where that sequence ends and restart interpreting characters as commands or data from that point.

~ is a vim command to toggle case of character under cursor.

A Happy Ending

Set TERM correctly (to match Putty/emulator settings) and ensure terminfo has a definition of PgUp etc. In Unix-land, keyboards existed before the IBM PC was born, some of them had a Previous Page key so this key capability is named kpp.

  $ infocmp xterm | grep kpp
    knp=\E[6~, kpp=\E[5~, kri=\E[1;2A, mc0=\E[i, mc4=\E[4i,


how to map these keys

Putty doesn't have an arbitrary key-mapping capability so far as I know (I think it was in the wish list) So ...

  1. Configure Putty to emulate a well-known and well-defined terminal type. Unfortunately there aren't any so something like xterm will have to do.

  2. Ensure Putty tells the Linux box what terminal type it is emulating. Partly this is by configuring Putty's settings and partly by using a protocol that communicates TERM (e.g. Putty's ssh support) rather than one that doesn't (Putty's telnet support).

  3. Ensure that TERM is actually set to what it should be (echo $TERM).

  4. Ensure the terminfo entry for that TERM values defines the keys you want (see above).

  5. Ensure the PgUp key sends what it should. In Vim enter insert mode and press Ctrl+V then PgUp

share|improve this answer
Thank you so much for the explanation. I solved this in my setup (Cygwin + Vim + Mintty) by putting set term=mintty in my vimrc file. – Sridhar-Sarnobat Feb 20 '14 at 0:38

Your Answer


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.