Last Updated: February 25, 2016
·
521
· gahtune

What Home button really meant to be

When coding I like to press home button to go to the first non-blank character, then if I press again the cursor go to the beginning of the line.

Here a small vim function to add this functionnality:

function! SuperHome()
    if (strpart(getline('.'), 0, col('.') - 1)=~'^\W*$')
        norm! 0
    else
        norm! ^
    endif
endfunction

nnoremap <silent> <Home> :call SuperHome()<CR>
inoremap <silent> <Home> <ESC>:call SuperHome()<CR>i
vnoremap <Home> omro<ESC>:call SuperHome()<CR>v`ro

Unfortunately for the visual mode, I need to use 1 marker (r). that may overwrite the previous defined marker.

Enjoy the tip ;p

EDIT: Here an up to date "mini-plugin" that include this tip: https://bitbucket.org/larchange/supernormal