1

I am using the CLI version of Vim on Mac mini, with OS X Lion.

I use Vim as my main code editor, and one thing that bother me is lack of Home and End keys for moving to the Start and End of lines, respectively. (On my laptop, the arrow keys left and right are home and end, with the Fn modifier)

I know Control + Arrows move screens, and Command + Arrows move through windows, so any way I can I can get Option or Fn + Arrows to do this?

I would really like something like this across all applications.

EDIT:

I answered this myself by basically following: theandystratton.com/2009/… I used the values supplied in the second comment too, which worked in both Vim and in general terminal too.

I wonder is there any drawbacks to using this...?

2 Answers 2

1

To remap home and end in Terminal, run f=~/Library/Preferences/com.apple.terminal.plist; plutil -convert xml1 $f; open $f -e, and change this:

<key>F729</key>
<string>scrollToBeginningOfDocument:</string>
<key>F72B</key>
<string>scrollToEndOfDocument:</string>

To this:

<key>F729</key>
<string>&#x1b;OH</string>
<key>F72B</key>
<string>&#x1b;OF</string>

To change them in normal text views, create ~/Library/KeyBindings/ and save a property list like this as DefaultKeyBinding.dict:

{
    "\UF729" = moveToBeginningOfParagraph:;
    "\UF72B" = moveToEndOfParagraph:;
    "$\UF729" = moveToBeginningOfParagraphAndModifySelection:;
    "$\UF72B" = moveToEndOfParagraphAndModifySelection:;
}

Another option would be to use KeyRemap4MacBook. See the "Use PC Style Home/End (except in Virtual Machine,RDC)" setting in https://raw.github.com/tekezo/KeyRemap4MacBook/master/Tests/lib/string/data/checkbox.xml.

0

In iTerm Fn + Left goes to the first character in the command you are typing, and Fn + Right goes to the end.

For vim, I would suggest mapping whatever key combination you want for 'Home' to 0 and similarly '$' for end.

If you are in insert mode, you can use imap to 'Esc'0i to leave insert mode and then jump to the beginning of the line, and re-enter insert mode.

Something like the following would add the maps for Fn+Left/Right to beginning/end of line for both normal and insert modes:

nmap ^[OF $

nmap ^[OH 0

imap ^[OF ^[$i

imap ^[OH ^[0i

Note: when entering special characters in the map use Ctrl-V first then enter the character-combination you want to map.

2
  • Thanks for the quick reply. For me, fn + Left seems to be jump to start of buffer, with fn + Right being jump to end of buffer. EDIT: Just tested it, and even with vim open, it scrolls to the top of buffer, leaving vim behind.
    – Thomas
    Jun 20, 2012 at 13:43
  • I use iTerm instead of the default terminal. I'll edit the answer above. Did you try adding the map commands to your .vimrc?
    – jmhindle
    Jun 20, 2012 at 14:10

You must log in to answer this question.

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