sponsor Vim development Vim logo Vim Book Ad

Smart Home Key : Home key toggles between ^ and 0

 script karma  Rating 23/12, Downloaded by 1047  Comments, bugs, improvements  Vim wiki

created by
andrew lyon
script type
This plugin will give you a command called :SmartHomeKey. You can bind this to any key, but I like to use <Home>. When you are in your code, and you call :SmartHomeKey, if the cursor is anywhere but ^ (the first non-blank character on the line), it will go to ^. If you are on ^ and you call :SmartHomeKey again, the cursor will be placed at 0 (first character on line, blank or non-blank). If you hold <Home>, it will just toggle between ^ and 0.

This emulates the behavior of the home key in Eclipse, which is what I used before switching to Vim.

This script is really simple, but I'm new to Vim scripting so let me know if you have problems (or if I did something stupid).
install details
Create ~/.vim/plugin/ (~\vimfiles\plugin\ on Win) if it doesn't exist. Drop in smarthomekey.vim. This will give you the command :SmartHomeKey which you can bind in your .vimrc:

map <silent> <Home> :SmartHomeKey <CR>
imap <silent> <Home> <C-O>:SmartHomeKey<CR>

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
smarthomekey.vim 0.2 2010-11-22 7.0 andrew lyon Fixed bug where the line number was being set incorrectly sometimes.
smarthomekey.vim 0.1 2010-11-22 7.0 andrew lyon Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.