Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

I want to have my external keyboard's HOME, END, PAGEDOWN and PAGEUP Working on Leopard's Terminal. So that I changed in Terminal > File > Preferences:

Home: \033[H  
End: \033[F  
PageUp: \033[5~  
PageDown: \033[6~

It works 100% in command line - but it doesn't work while editing files in VIM.
Is there any possibility of remapping VIM keyboard in order to have these keys working?


share|improve this question
Should be SuperUser? – wfaulk Oct 9 '09 at 17:48
up vote 2 down vote accepted

If, according to the question, you already know the mappings, then it's easy..

Home: \033[H  
End: \033[F  
PageUp: \033[5~  
PageDown: \033[6~

Just edit ~/.vimrc and add:

map <Esc>[H <Home>
imap <Esc>[H <Home>
map <Esc>[F <End>
imap <Esc>[F <End>
map <Esc>[5~ <PageUp>
imap <Esc>[5~ <PageUp>
map <Esc>[6~ <PageDown>
imap <Esc>[6~ <PageDown>
share|improve this answer


:imap <C-k><Home> <Home>
:map <C-k><Home> <Home>

-- actually hitting control-k and your home key for both, to enter what vim reads from your home key, then typing the second <Home>. And so on for the other bindings. See :help :map and :help <>.

share|improve this answer
How can I permanently save such modifications in my vi configuration? – jbastos Oct 10 '09 at 13:11
In my case, I prefer hitting control-v instead of control-k . – jbastos Oct 10 '09 at 14:24
C-v is what I'm used to, and tried, but gvim binds it differently on windows. C-k is advertised to do the same for 'special keys'. – ayrnieu Oct 10 '09 at 14:42

I have permanently solved it.

In my case, I have mapped it in vim:

:imap <C-v><Home> <Home>
:map <C-v><Home> <Home>

-- actually hitting control-v and your home key for both, to enter what vim reads from my home key, then typing the second .

It works, but it lasts only for the current session.
So, I just type the following command, followed by <Enter>


Then I get the mappings

<Esc>[H <Home>

Now, I just add it to my ~/.vimrc file:

map <Esc>[H <Home>
imap <Esc>[H <Home>

now it is remapped to all vim sessions of my user.

share|improve this answer
reference: – jbastos Oct 10 '09 at 14:34

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.