I am pretty new to Vim and to Mac, I have a MacBook Pro with Retina Display running OS X 10.8.3, which does NOT have native Home, End, PageUp and PageDown keys.

I know the Fn + arrow keys can work in some applications. Also in bash, I can use Ctrl + A go to the beginning of the command line I am typing and Ctrl + E go to the end.

But in Vim with INSERT/edit Mode, all these works differently. I don't want to always switch to the Normal Mode using 0 and $ or I and A. (Or, is this the best way?)

So can anyone show me some tricks to map some hotkeys that can works conveniently? Or some other solutions? ( But please without MacVim, I want to try native Vim for a while first:) )?

Any other tips for Home, End, PageUp and PageDown functions under the Mac also welcome.


Go to Terminal -> Preferences -> Profiles -> Keyboard and add:

Key: ↖ Action: \033OH

Key: ↗ Action: \033OF


Vim allows you to map any key sequence to other key sequence using :map command. There are several types of this command, that can be used to create shortcuts only for some vim modes. Check out this page and/or :help map command inside vim for details.

About your questions there are two ways in vim to implement Home behaviour:

  • 0 (zero) to go to the very first column
  • ^ to go to the column with the first non-whitespace character on a given line

For End you can use $. For PageUp and PageDown you can use Ctrl+F and Ctrl+B respectively.

This keys only work in command mode, but you can remap it to use in insert mode with :imap ('i' here is for insert-mode) and Ctrl+F. For example, to map Ctrl+A to act as 0 use this command:

:imap <C-a> <C-o>0

It's a very standard vim command and must work like a charm in console vim, gvim, mvim etc.


Just one tip. By default bash runs in "emacs mode". You can change it to "vi mode". Bash uses the readline package to edit your command line, for more details read the "READLINE" section of the bash man page.

In short you can redefine a lot of the key bindings in a file called .inputrc which should live in your home folder.

readline is also used by a number of other utilities and places such as the interactive python shell.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .