Skip to content

Instantly share code, notes, and snippets.

@c9s
Created October 20, 2009 19:22
Show Gist options
  • Save c9s/214532 to your computer and use it in GitHub Desktop.
Save c9s/214532 to your computer and use it in GitHub Desktop.
"smart home function
function! SmartHome(mode)
let curcol = col(".")
if &wrap
normal! g^
else
normal! ^
endif
if col(".") == curcol
if &wrap
normal! g0
else
normal! 0
endif
endif
if a:mode == "v"
normal msgv`s
endif
return ""
endfunction
"smart end function
function! SmartEnd(mode)
let curcol = col(".")
let lastcol = a:mode == "i" ? col("$") : col("$") - 1
"gravitate towards ending for wrapped lines
if curcol < lastcol - 1
call cursor(0, curcol + 1)
endif
if curcol < lastcol
if &wrap
normal g$
else
normal $
endif
else
normal g_
endif
"correct edit mode cursor position, put after current character
if a:mode == "i"
call cursor(0, col(".") + 1)
endif
if a:mode == "v"
normal msgv`s
endif
return ""
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment