" Dynamic bind <HOME> key
" if caret/cursor not at the frist non-white-space character
" move caret/cursor to there
" else
" move to beginning
function HomeBind(offset)
let cursor=getpos('.')
let s0=getline(line('.'))
let s1=substitute(s0, "^\\s\\+", "", "")
let x=len(s0)-len(s1)+1
if col('.') == x-a:offset
let x=1
endif
call setpos('.', [cursor[0], cursor[1], x, cursor[3]])
endfunction
imap <silent> <Home> <Esc>:call HomeBind(1)<cr>i
nmap <silent> <Home> :call HomeBind(0)<cr>
vmap <silent> <Home> <Esc>:call HomeBind(1)<cr>
" Dynamic bind <END> key
" if caret/cursor not at the end
" move caret/cursor to there
" else
" move to last non-white-space character.
function EndBind(offset)
let cursor=getpos('.')
let s0=getline(line('.'))
let s1=substitute(s0, "\\s*$", "", "")
let x=len(s0)+a:offset
if col('.') == x
let x=len(s1)+a:offset
endif
call setpos('.', [cursor[0], cursor[1], x, cursor[3]])
endfunction
imap <silent> <End> <Esc>:call EndBind(0)<cr>a
nmap <silent> <End> :call EndBind(0)<cr>
vmap <silent> <End> :call EndBind(0)<cr>
"nmap <End> /\S\s*$<CR>:nohl<CR>