Created
October 20, 2009 19:22
-
-
Save c9s/214532 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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