Merge pull request #221 from Vadskye/master

Use mapping helper function for almost all mappings
This commit is contained in:
haya14busa 2015-04-21 10:46:34 +09:00
commit 9f1c449edf

View File

@ -59,19 +59,33 @@ let g:EasyMotion_disable_two_key_combo =
" Note: bd is short for bidirectional " Note: bd is short for bidirectional
" l is short for (within) line " l is short for (within) line
function! s:find_motion_map_helper(motions) "{{{ function! s:motion_map_helper(motions) "{{{
for [name, dict] in items(a:motions) for [name, dict] in items(a:motions)
let mapargs = []
let xmapargs = []
if dict.fnc ==# 'S' || dict.fnc ==# 'SL' || dict.fnc ==# 'T' || dict.fnc ==# 'TL'
let mapargs += [dict.cnt, 0, dict.direction]
let xmapargs += [dict.cnt, 1, dict.direction]
elseif dict.fnc ==# 'Search'
let mapargs += [0, dict.direction, dict.respect_direction]
let xmapargs += [1, dict.direction, dict.respect_direction]
else
let mapargs += [0, dict.direction]
let xmapargs += [1, dict.direction]
endif
silent exec 'noremap <silent><Plug>(easymotion-'.name.')' . silent exec 'noremap <silent><Plug>(easymotion-'.name.')' .
\ ' :<C-u>call EasyMotion#'. dict.fnc .'('. dict.cnt .',0,'. dict.direction .')<CR>' \ ' :<C-u>call EasyMotion#' . dict.fnc . '('. join(mapargs, ',') . ')<CR>'
silent exec 'xnoremap <silent><Plug>(easymotion-'.name.')' . silent exec 'xnoremap <silent><Plug>(easymotion-'.name.')' .
\ ' <Esc>:<C-u>call EasyMotion#'. dict.fnc .'('. dict.cnt .',1,'. dict.direction .')<CR>' \ ' <Esc>:<C-u>call EasyMotion#' . dict.fnc . '('. join(xmapargs, ',') . ')<CR>'
" Example: " Example:
" noremap <silent><Plug>(easymotion-f2) :<C-u>call EasyMotion#S(2,1,0)<CR> " noremap <silent><Plug>(easymotion-f2) :<C-u>call EasyMotion#S(2,1,0)<CR>
" xnoremap <silent><Plug>(easymotion-f2) <Esc>:<C-u>call EasyMotion#S(2,1,0)<CR> " xnoremap <silent><Plug>(easymotion-f2) <Esc>:<C-u>call EasyMotion#S(2,1,0)<CR>
endfor endfor
endfunction "}}} endfunction "}}}
" Find Motion: {{{ " Find Motion: {{{
call s:find_motion_map_helper({ call s:motion_map_helper({
\ 'f' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 0}, \ 'f' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 0},
\ 'F' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 1}, \ 'F' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 1},
\ 's' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 2}, \ 's' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 2},
@ -120,119 +134,71 @@ call s:find_motion_map_helper({
"}}} "}}}
" -- Word Motion {{{ " -- Word Motion {{{
" Word: {{{ call s:motion_map_helper({
noremap <silent><Plug>(easymotion-w) :<C-u>call EasyMotion#WB(0,0)<CR> \ 'w' : {'fnc' : 'WB' , 'direction' : 0},
xnoremap <silent><Plug>(easymotion-w) <Esc>:<C-u>call EasyMotion#WB(1,0)<CR> \ 'b' : {'fnc' : 'WB' , 'direction' : 1},
noremap <silent><Plug>(easymotion-b) :<C-u>call EasyMotion#WB(0,1)<CR> \ 'bd-w' : {'fnc' : 'WB' , 'direction' : 2},
xnoremap <silent><Plug>(easymotion-b) <Esc>:<C-u>call EasyMotion#WB(1,1)<CR> \ 'W' : {'fnc' : 'WBW', 'direction' : 0},
noremap <silent><Plug>(easymotion-bd-w) :<C-u>call EasyMotion#WB(0,2)<CR> \ 'B' : {'fnc' : 'WBW', 'direction' : 1},
xnoremap <silent><Plug>(easymotion-bd-w) <Esc>:<C-u>call EasyMotion#WB(1,2)<CR> \ 'bd-W' : {'fnc' : 'WBW', 'direction' : 2},
"}}} \ 'iskeyword-w' : {'fnc' : 'WBK', 'direction' : 0},
\ 'iskeyword-b' : {'fnc' : 'WBK', 'direction' : 1},
" WORD: {{{ \ 'iskeyword-bd-w' : {'fnc' : 'WBK', 'direction' : 2},
noremap <silent><Plug>(easymotion-W) :<C-u>call EasyMotion#WBW(0,0)<CR> \
xnoremap <silent><Plug>(easymotion-W) <Esc>:<C-u>call EasyMotion#WBW(1,0)<CR> \ 'e' : {'fnc' : 'E' , 'direction' : 0},
noremap <silent><Plug>(easymotion-B) :<C-u>call EasyMotion#WBW(0,1)<CR> \ 'ge' : {'fnc' : 'E' , 'direction' : 1},
xnoremap <silent><Plug>(easymotion-B) <Esc>:<C-u>call EasyMotion#WBW(1,1)<CR> \ 'bd-e' : {'fnc' : 'E' , 'direction' : 2},
noremap <silent><Plug>(easymotion-bd-W) :<C-u>call EasyMotion#WBW(0,2)<CR> \ 'E' : {'fnc' : 'EW' , 'direction' : 0},
xnoremap <silent><Plug>(easymotion-bd-W) <Esc>:<C-u>call EasyMotion#WBW(1,2)<CR> \ 'gE' : {'fnc' : 'EW' , 'direction' : 1},
"}}} \ 'bd-E' : {'fnc' : 'EW' , 'direction' : 2},
\ 'iskeyword-e' : {'fnc' : 'EK' , 'direction' : 0},
" iskeyword {{{ \ 'iskeyword-ge' : {'fnc' : 'EK' , 'direction' : 1},
noremap <silent><Plug>(easymotion-iskeyword-w) :<C-u>call EasyMotion#WBK(0,0)<CR> \ 'iskeyword-bd-e' : {'fnc' : 'EK' , 'direction' : 2},
xnoremap <silent><Plug>(easymotion-iskeyword-w) <Esc>:<C-u>call EasyMotion#WBK(1,0)<CR> \ })
noremap <silent><Plug>(easymotion-iskeyword-b) :<C-u>call EasyMotion#WBK(0,1)<CR>
xnoremap <silent><Plug>(easymotion-iskeyword-b) <Esc>:<C-u>call EasyMotion#WBK(1,1)<CR>
noremap <silent><Plug>(easymotion-iskeyword-bd-w) :<C-u>call EasyMotion#WBK(0,2)<CR>
xnoremap <silent><Plug>(easymotion-iskeyword-bd-w) <Esc>:<C-u>call EasyMotion#WBK(1,2)<CR>
" }}}
" End Word: {{{
noremap <silent><Plug>(easymotion-e) :<C-u>call EasyMotion#E(0,0)<CR>
xnoremap <silent><Plug>(easymotion-e) <Esc>:<C-u>call EasyMotion#E(1,0)<CR>
noremap <silent><Plug>(easymotion-ge) :<C-u>call EasyMotion#E(0,1)<CR>
xnoremap <silent><Plug>(easymotion-ge) <Esc>:<C-u>call EasyMotion#E(1,1)<CR>
noremap <silent><Plug>(easymotion-bd-e) :<C-u>call EasyMotion#E(0,2)<CR>
xnoremap <silent><Plug>(easymotion-bd-e) <Esc>:<C-u>call EasyMotion#E(1,2)<CR>
"}}}
" END WORD: {{{
noremap <silent><Plug>(easymotion-E) :<C-u>call EasyMotion#EW(0,0)<CR>
xnoremap <silent><Plug>(easymotion-E) <Esc>:<C-u>call EasyMotion#EW(1,0)<CR>
noremap <silent><Plug>(easymotion-gE) :<C-u>call EasyMotion#EW(0,1)<CR>
xnoremap <silent><Plug>(easymotion-gE) <Esc>:<C-u>call EasyMotion#EW(1,1)<CR>
noremap <silent><Plug>(easymotion-bd-E) :<C-u>call EasyMotion#EW(0,2)<CR>
xnoremap <silent><Plug>(easymotion-bd-E) <Esc>:<C-u>call EasyMotion#EW(1,2)<CR>
"}}}
" iskeyword End: {{{
noremap <silent><Plug>(easymotion-iskeyword-e) :<C-u>call EasyMotion#EK(0,0)<CR>
xnoremap <silent><Plug>(easymotion-iskeyword-e) <Esc>:<C-u>call EasyMotion#EK(1,0)<CR>
noremap <silent><Plug>(easymotion-iskeyword-ge) :<C-u>call EasyMotion#EK(0,1)<CR>
xnoremap <silent><Plug>(easymotion-iskeyword-ge) <Esc>:<C-u>call EasyMotion#EK(1,1)<CR>
noremap <silent><Plug>(easymotion-iskeyword-bd-e) :<C-u>call EasyMotion#EK(0,2)<CR>
xnoremap <silent><Plug>(easymotion-iskeyword-bd-e) <Esc>:<C-u>call EasyMotion#EK(1,2)<CR>
"}}}
"}}} "}}}
" -- JK Motion {{{ " -- JK Motion {{{
noremap <silent><Plug>(easymotion-j) :<C-u>call EasyMotion#JK(0,0)<CR> call s:motion_map_helper({
xnoremap <silent><Plug>(easymotion-j) <Esc>:<C-u>call EasyMotion#JK(1,0)<CR> \ 'j' : {'fnc' : 'JK' , 'direction' : 0},
noremap <silent><Plug>(easymotion-k) :<C-u>call EasyMotion#JK(0,1)<CR> \ 'k' : {'fnc' : 'JK' , 'direction' : 1},
xnoremap <silent><Plug>(easymotion-k) <Esc>:<C-u>call EasyMotion#JK(1,1)<CR> \ 'bd-jk' : {'fnc' : 'JK' , 'direction' : 2},
noremap <silent><Plug>(easymotion-bd-jk) :<C-u>call EasyMotion#JK(0,2)<CR> \ 'sol-j' : {'fnc' : 'Sol', 'direction' : 0},
xnoremap <silent><Plug>(easymotion-bd-jk) <Esc>:<C-u>call EasyMotion#JK(1,2)<CR> \ 'sol-k' : {'fnc' : 'Sol', 'direction' : 1},
\ 'sol-bd-jk' : {'fnc' : 'Sol', 'direction' : 2},
" Start of Line JK {{{ \ 'eol-j' : {'fnc' : 'Eol', 'direction' : 0},
noremap <silent><Plug>(easymotion-sol-j) :<C-u>call EasyMotion#Sol(0,0)<CR> \ 'eol-k' : {'fnc' : 'Eol', 'direction' : 1},
xnoremap <silent><Plug>(easymotion-sol-j) <Esc>:<C-u>call EasyMotion#Sol(1,0)<CR> \ 'eol-bd-jk' : {'fnc' : 'Eol', 'direction' : 2},
noremap <silent><Plug>(easymotion-sol-k) :<C-u>call EasyMotion#Sol(0,1)<CR> \ })
xnoremap <silent><Plug>(easymotion-sol-k) <Esc>:<C-u>call EasyMotion#Sol(1,1)<CR>
noremap <silent><Plug>(easymotion-sol-bd-jk) :<C-u>call EasyMotion#Sol(0,2)<CR>
xnoremap <silent><Plug>(easymotion-sol-bd-jk) <Esc>:<C-u>call EasyMotion#Sol(1,2)<CR>
"}}}
" End of Line JK {{{
noremap <silent><Plug>(easymotion-eol-j) :<C-u>call EasyMotion#Eol(0,0)<CR>
xnoremap <silent><Plug>(easymotion-eol-j) <Esc>:<C-u>call EasyMotion#Eol(1,0)<CR>
noremap <silent><Plug>(easymotion-eol-k) :<C-u>call EasyMotion#Eol(0,1)<CR>
xnoremap <silent><Plug>(easymotion-eol-k) <Esc>:<C-u>call EasyMotion#Eol(1,1)<CR>
noremap <silent><Plug>(easymotion-eol-bd-jk) :<C-u>call EasyMotion#Eol(0,2)<CR>
xnoremap <silent><Plug>(easymotion-eol-bd-jk) <Esc>:<C-u>call EasyMotion#Eol(1,2)<CR>
"}}}
"}}} "}}}
" -- Search Motion {{{ " -- Search Motion {{{
noremap <silent><Plug>(easymotion-n) :<C-u>call EasyMotion#Search(0,0,0)<CR> call s:motion_map_helper({
xnoremap <silent><Plug>(easymotion-n) <Esc>:<C-u>call EasyMotion#Search(1,0,0)<CR> \ 'n' : {'fnc' : 'Search', 'direction': 0, 'respect_direction': 0},
noremap <silent><Plug>(easymotion-N) :<C-u>call EasyMotion#Search(0,1,0)<CR> \ 'N' : {'fnc' : 'Search', 'direction': 1, 'respect_direction': 0},
xnoremap <silent><Plug>(easymotion-N) <Esc>:<C-u>call EasyMotion#Search(1,1,0)<CR> \ 'bd-n' : {'fnc' : 'Search', 'direction': 2, 'respect_direction': 0},
\ 'vim-n' : {'fnc' : 'Search', 'direction': 0, 'respect_direction': 1},
noremap <silent><Plug>(easymotion-vim-n) :<C-u>call EasyMotion#Search(0,0,1)<CR> \ 'vim-N' : {'fnc' : 'Search', 'direction': 1, 'respect_direction': 1},
xnoremap <silent><Plug>(easymotion-vim-n) <Esc>:<C-u>call EasyMotion#Search(1,0,1)<CR> \ })
noremap <silent><Plug>(easymotion-vim-N) :<C-u>call EasyMotion#Search(0,1,1)<CR>
xnoremap <silent><Plug>(easymotion-vim-N) <Esc>:<C-u>call EasyMotion#Search(1,1,1)<CR>
noremap <silent><Plug>(easymotion-bd-n) :<C-u>call EasyMotion#Search(0,2,0)<CR>
xnoremap <silent><Plug>(easymotion-bd-n) <Esc>:<C-u>call EasyMotion#Search(1,2,0)<CR>
"}}} "}}}
" -- Jump To Anywhere Motion {{{ " -- Jump To Anywhere Motion {{{
noremap <silent><Plug>(easymotion-jumptoanywhere) call s:motion_map_helper({
\ :<C-u>call EasyMotion#JumpToAnywhere(0,2)<CR> \ 'jumptoanywhere' : {'fnc' : 'JumpToAnywhere', 'direction': 2},
xnoremap <silent><Plug>(easymotion-jumptoanywhere) \ })
\ <Esc>:<C-u>call EasyMotion#JumpToAnywhere(1,2)<CR>
"}}} "}}}
" -- Repeat Motion {{{ " -- Line Motion {{{
noremap <silent><Plug>(easymotion-repeat) call s:motion_map_helper({
\ :<C-u>call EasyMotion#Repeat(0)<CR> \ 'wl' : {'fnc' : 'WBL', 'direction': 0},
xnoremap <silent><Plug>(easymotion-repeat) \ 'bl' : {'fnc' : 'WBL', 'direction': 1},
\ <Esc>:<C-u>call EasyMotion#Repeat(1)<CR> \ 'bd-wl' : {'fnc' : 'WBL', 'direction': 2},
\ 'el' : {'fnc' : 'EL' , 'direction': 0},
noremap <silent><Plug>(easymotion-dotrepeat) \ 'gel' : {'fnc' : 'EL' , 'direction': 1},
\ :<C-u>call EasyMotion#DotRepeat()<CR> \ 'bd-el' : {'fnc' : 'EL' , 'direction': 2},
\ 'lineforward' : {'fnc' : 'LineAnywhere', 'direction': 0},
\ 'linebackward' : {'fnc' : 'LineAnywhere', 'direction': 1},
\ 'lineanywhere' : {'fnc' : 'LineAnywhere', 'direction': 2},
\ })
"}}} "}}}
" -- Next, Previous Motion {{{ " -- Next, Previous Motion {{{
@ -247,47 +213,18 @@ xnoremap <silent><Plug>(easymotion-prev)
\ :<C-u>call EasyMotion#NextPrevious(1,1)<CR> \ :<C-u>call EasyMotion#NextPrevious(1,1)<CR>
"}}} "}}}
" -- Line Motion {{{ " -- Repeat Motion {{{
" Word Line: {{{ noremap <silent><Plug>(easymotion-repeat)
noremap <silent><Plug>(easymotion-wl) :<C-u>call EasyMotion#WBL(0,0)<CR> \ :<C-u>call EasyMotion#Repeat(0)<CR>
xnoremap <silent><Plug>(easymotion-wl) <Esc>:<C-u>call EasyMotion#WBL(1,0)<CR> xnoremap <silent><Plug>(easymotion-repeat)
noremap <silent><Plug>(easymotion-bl) :<C-u>call EasyMotion#WBL(0,1)<CR> \ <Esc>:<C-u>call EasyMotion#Repeat(1)<CR>
xnoremap <silent><Plug>(easymotion-bl) <Esc>:<C-u>call EasyMotion#WBL(1,1)<CR>
noremap <silent><Plug>(easymotion-bd-wl) :<C-u>call EasyMotion#WBL(0,2)<CR>
xnoremap <silent><Plug>(easymotion-bd-wl) <Esc>:<C-u>call EasyMotion#WBL(1,2)<CR>
"}}}
" End Word Line: {{{ noremap <silent><Plug>(easymotion-dotrepeat)
noremap <silent><Plug>(easymotion-el) :<C-u>call EasyMotion#EL(0,0)<CR> \ :<C-u>call EasyMotion#DotRepeat()<CR>
xnoremap <silent><Plug>(easymotion-el) <Esc>:<C-u>call EasyMotion#EL(1,0)<CR>
noremap <silent><Plug>(easymotion-gel) :<C-u>call EasyMotion#EL(0,1)<CR>
xnoremap <silent><Plug>(easymotion-gel) <Esc>:<C-u>call EasyMotion#EL(1,1)<CR>
noremap <silent><Plug>(easymotion-bd-el) :<C-u>call EasyMotion#EL(0,2)<CR>
xnoremap <silent><Plug>(easymotion-bd-el) <Esc>:<C-u>call EasyMotion#EL(1,2)<CR>
"}}}
" LineAnywhere Line: {{{
noremap <silent><Plug>(easymotion-lineforward)
\ :<C-u>call EasyMotion#LineAnywhere(0,0)<CR>
xnoremap <silent><Plug>(easymotion-lineforward)
\ <Esc>:<C-u>call EasyMotion#LineAnywhere(1,0)<CR>
noremap <silent><Plug>(easymotion-linebackward)
\ :<C-u>call EasyMotion#LineAnywhere(0,1)<CR>
xnoremap <silent><Plug>(easymotion-linebackward)
\ <Esc>:<C-u>call EasyMotion#LineAnywhere(1,1)<CR>
noremap <silent><Plug>(easymotion-lineanywhere)
\ :<C-u>call EasyMotion#LineAnywhere(0,2)<CR>
xnoremap <silent><Plug>(easymotion-lineanywhere)
\ <Esc>:<C-u>call EasyMotion#LineAnywhere(1,2)<CR>
"}}}
"}}} "}}}
noremap <silent><Plug>(easymotion-activate) :<C-u>call EasyMotion#activate(0)<CR> noremap <silent><Plug>(easymotion-activate) :<C-u>call EasyMotion#activate(0)<CR>
xnoremap <silent><Plug>(easymotion-activate) :<C-u>call EasyMotion#activate(1)<CR> xnoremap <silent><Plug>(easymotion-activate) :<C-u>call EasyMotion#activate(1)<CR>
" }}} " }}}
" == Default key mapping {{{ " == Default key mapping {{{