Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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.

share|improve this answer

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.

share|improve this answer

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.