diff --git a/plugin/EasyMotion.vim b/plugin/EasyMotion.vim index 251d954..c24ecc6 100644 --- a/plugin/EasyMotion.vim +++ b/plugin/EasyMotion.vim @@ -55,22 +55,26 @@ " }}} " Default key mapping {{{ if g:EasyMotion_do_mapping - nnoremap f :call EasyMotionF(0) - vnoremap f :call EasyMotionF(0, visualmode()) - nnoremap F :call EasyMotionF(1) - vnoremap F :call EasyMotionF(1, visualmode()) + nnoremap f :call EasyMotionF(0, 0) + vnoremap f :call EasyMotionF(0, 1) - nnoremap t :call EasyMotionT(0) - vnoremap t :call EasyMotionT(0, visualmode()) - nnoremap T :call EasyMotionT(1) - vnoremap T :call EasyMotionT(1, visualmode()) + nnoremap F :call EasyMotionF(1, 0) + vnoremap F :call EasyMotionF(1, 1) - nnoremap w :call EasyMotionW() - vnoremap w :call EasyMotionW(visualmode()) - nnoremap e :call EasyMotionE() - vnoremap e :call EasyMotionE(visualmode()) - nnoremap b :call EasyMotionB() - vnoremap b :call EasyMotionB(visualmode()) + nnoremap t :call EasyMotionT(0, 0) + vnoremap t :call EasyMotionT(0, 1) + + nnoremap T :call EasyMotionT(1, 0) + vnoremap T :call EasyMotionT(1, 1) + + nnoremap w :call EasyMotionW(0) + vnoremap w :call EasyMotionW(1) + + nnoremap e :call EasyMotionE(0) + vnoremap e :call EasyMotionE(1) + + nnoremap b :call EasyMotionB(0) + vnoremap b :call EasyMotionB(1) endif " }}} " Initialize variables {{{ @@ -88,19 +92,19 @@ " Motion functions {{{ " F key motions {{{ " Go to {char} to the right or the left - function! EasyMotionF(direction, ...) + function! EasyMotionF(direction, visualmode) call Prompt('Search for character') let char = getchar() let re = '\C' . escape(nr2char(char), '.$^~') - call EasyMotion(re, a:direction, a:0 > 0 ? a:1 : '') + call EasyMotion(re, a:direction, a:visualmode ? visualmode() : '') endfunction " }}} " T key motions {{{ " Go to {char} to the right (before) or the left (after) - function! EasyMotionT(direction, ...) + function! EasyMotionT(direction, visualmode) call Prompt('Search for character') let char = getchar() @@ -111,25 +115,25 @@ let re = '\C.' . escape(nr2char(char), '.$^~') endif - call EasyMotion(re, a:direction, a:0 > 0 ? a:1 : '') + call EasyMotion(re, a:direction, a:visualmode ? visualmode() : '') endfunction " }}} " W key motions {{{ " Beginning of word forward - function! EasyMotionW(...) - call EasyMotion('\<.', 0, a:0 > 0 ? a:1 : '') + function! EasyMotionW(visualmode) + call EasyMotion('\<.', 0, a:visualmode ? visualmode() : '') endfunction " }}} " E key motions {{{ " End of word forward - function! EasyMotionE(...) - call EasyMotion('.\>', 0, a:0 > 0 ? a:1 : '') + function! EasyMotionE(visualmode) + call EasyMotion('.\>', 0, a:visualmode ? visualmode() : '') endfunction " }}} " B key motions {{{ " Beginning of word backward - function! EasyMotionB(...) - call EasyMotion('\<.', 1, a:0 > 0 ? a:1 : '') + function! EasyMotionB(visualmode) + call EasyMotion('\<.', 1, a:visualmode ? visualmode() : '') endfunction " }}} " }}} @@ -255,10 +259,9 @@ endif endtry endfunction "}}} - function! s:EasyMotion(regexp, direction, ...) " {{{ + function! s:EasyMotion(regexp, direction, visualmode) " {{{ let orig_pos = [line('.'), col('.')] let targets = [] - let visualmode = a:0 > 0 ? a:1 : '' try " Reset properties @@ -341,7 +344,7 @@ if len(coords) != 2 throw 'Cancelled' else - if ! empty(visualmode) + if ! empty(a:visualmode) " Store original marks let m_a = getpos("'a") let m_b = getpos("'b") @@ -351,7 +354,7 @@ call setpos("'b", [0, coords[0], coords[1]]) " Update selection - silent exec 'normal! `a' . visualmode . '`b' + silent exec 'normal! `a' . a:visualmode . '`b' " Restore original marks call setpos("'a", m_a) @@ -370,8 +373,8 @@ call Message(v:exception) " Restore cursor position/selection - if ! empty(visualmode) - silent exec 'normal! `<' . visualmode . '`>' + if ! empty(a:visualmode) + silent exec 'normal! `<' . a:visualmode . '`>' else call setpos('.', [0, orig_pos[0], orig_pos[1]]) endif