In terminal I can do this by pressing shift+home and shift+end, but it doesn't seem to work in vim. Home and end keys scroll terminal window only. I would like to jump in edit mode.

link|improve this question

57% accept rate
3  
In command mode, you can find on the Vim Cheat Sheet (0 and $): fprintf.net/vimCheatSheet.html. I don't know about edit mode, though. – Gnoupi Mar 25 '10 at 10:48
feedback

2 Answers

up vote 4 down vote accepted

This answer assumes you are using vim in a Terminal window.

The default bindings for Home and End are a bit different from what a program would expect based on the usual TERM setting (i.e. an xterm variant). If you want to stick with the default bindings (and having to use the Shifted variants in Terminal), you might try putting something like this in your .vimrc:

:" map Mac OS X Terminal.app default Home and End
:map <ESC>[H <Home>
:map <ESC>[F <End>
:imap <ESC>[H <C-O><Home>
:imap <ESC>[F <C-O><End>
:cmap <ESC>[H <Home>
:cmap <ESC>[F <End>

Otherwise, you might try adjusting the codes that Terminal sends when you use Home and End (unshifted even, if you like). A search would probably turn up some places that describe how to do it (here is one). The basic idea is that you want to have Terminal send ESC[1~ instead of ESC[H for Home and ESC[4~ instead of ESC[F for End (or Shift-Home/Shift-End if you want to keep Home/End for accessing scrollback). I would describe the process in more detail, but I only have 10.4, and I know Terminal was changed a lot in 10.5 and later.

link|improve this answer
Works perfectly, thank you very much!! – JtR Mar 25 '10 at 14:53
feedback

In MacVim, you can use Command 'Left Arrow' and Command 'Right Arrow' to go to the beginning and end of line while being in edit mode.

link|improve this answer
Sounds like JtR is using vim inside Terminal.app instead of using MacVim (which I would highly recommend, and personally use, as well). – Matrix Mole Mar 25 '10 at 11:57
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.