vim-easymotion/plugin/EasyMotion.vim

288 lines
13 KiB
VimL
Raw Normal View History

2014-09-10 07:12:39 -04:00
scriptencoding utf-8
2011-03-28 04:18:00 -04:00
" EasyMotion - Vim motions on speed!
2011-03-27 18:08:06 -04:00
"
2011-03-29 08:10:00 -04:00
" Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com>
2014-02-01 12:26:06 -05:00
" haya14busa <hayabusa1419@gmail.com>
2015-06-22 10:04:30 -04:00
" Source: https://github.com/easymotion/vim-easymotion
" == Script initialization {{{
2014-01-20 16:30:30 -05:00
if expand("%:p") ==# expand("<sfile>:p")
unlet! g:EasyMotion_loaded
endif
if exists('g:EasyMotion_loaded') || &compatible || version < 703
finish
endif
2011-03-27 18:08:06 -04:00
let g:EasyMotion_loaded = 1
2011-03-27 18:08:06 -04:00
" }}}
" == Saving 'cpoptions' {{{
2013-12-18 07:32:27 -05:00
let s:save_cpo = &cpo
set cpo&vim
" }}}
" == Default configuration {{{
" -- Option ------------------------------ {{{
let g:EasyMotion_keys = get(g:,
\ 'EasyMotion_keys', 'asdghklqwertyuiopzxcvbnmfj;')
" \ 'EasyMotion_keys', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
let g:EasyMotion_do_mapping = get(g: , 'EasyMotion_do_mapping' , 1)
let g:EasyMotion_do_shade = get(g: , 'EasyMotion_do_shade' , 1)
let g:EasyMotion_grouping = get(g: , 'EasyMotion_grouping' , 1)
let g:EasyMotion_startofline = get(g: , 'EasyMotion_startofline' , 1)
let g:EasyMotion_smartcase = get(g: , 'EasyMotion_smartcase' , 0)
let g:EasyMotion_skipfoldedline = get(g: , 'EasyMotion_skipfoldedline' , 1)
let g:EasyMotion_use_migemo = get(g: , 'EasyMotion_use_migemo' , 0)
let g:EasyMotion_use_upper = get(g: , 'EasyMotion_use_upper' , 0)
let g:EasyMotion_enter_jump_first = get(g: , 'EasyMotion_enter_jump_first' , 0)
let g:EasyMotion_space_jump_first = get(g: , 'EasyMotion_space_jump_first' , 0)
let g:EasyMotion_inc_highlight = get(g: , 'EasyMotion_inc_highlight' , 1)
let g:EasyMotion_move_highlight = get(g: , 'EasyMotion_move_highlight' , 1)
let g:EasyMotion_landing_highlight = get(g: , 'EasyMotion_landing_highlight' , 0)
let g:EasyMotion_cursor_highlight = get(g: , 'EasyMotion_cursor_highlight' , 1)
let g:EasyMotion_use_regexp = get(g: , 'EasyMotion_use_regexp' , 1)
let g:EasyMotion_add_search_history = get(g: , 'EasyMotion_add_search_history' , 1)
let g:EasyMotion_off_screen_search = get(g: , 'EasyMotion_off_screen_search' , 1)
2014-05-26 00:35:37 -04:00
let g:EasyMotion_force_csapprox = get(g: , 'EasyMotion_force_csapprox' , 0)
2014-01-13 16:29:36 -05:00
let g:EasyMotion_show_prompt = get(g: , 'EasyMotion_show_prompt' , 1)
let g:EasyMotion_prompt =
\ get(g: , 'EasyMotion_prompt' , 'Search for {n} character(s): ')
let g:EasyMotion_command_line_key_mappings =
\ get(g: , 'EasyMotion_command_line_key_mappings' , {})
let g:EasyMotion_disable_two_key_combo =
\ get(g: , 'EasyMotion_disable_two_key_combo' , 0)
"}}}
" }}}
" == <Plug> Mapping {{{
" Note: bd is short for bidirectional
" l is short for (within) line
function! s:motion_map_helper(motions) "{{{
2014-05-26 00:35:37 -04:00
for [name, dict] in items(a:motions)
2015-04-20 12:48:38 -04:00
let mapargs = []
let xmapargs = []
if dict.fnc ==# 'S' || dict.fnc ==# 'SL' || dict.fnc ==# 'T' || dict.fnc ==# 'TL'
2015-04-20 12:48:38 -04:00
let mapargs += [dict.cnt, 0, dict.direction]
let xmapargs += [dict.cnt, 1, dict.direction]
elseif dict.fnc ==# 'Search'
2015-04-20 12:48:38 -04:00
let mapargs += [0, dict.direction, dict.respect_direction]
let xmapargs += [1, dict.direction, dict.respect_direction]
else
2015-04-20 12:48:38 -04:00
let mapargs += [0, dict.direction]
let xmapargs += [1, dict.direction]
endif
2014-01-13 14:29:09 -05:00
silent exec 'noremap <silent><Plug>(easymotion-'.name.')' .
\ ' :<C-u>call EasyMotion#' . dict.fnc . '('. join(mapargs, ',') . ')<CR>'
2014-01-13 14:29:09 -05:00
silent exec 'xnoremap <silent><Plug>(easymotion-'.name.')' .
\ ' <Esc>:<C-u>call EasyMotion#' . dict.fnc . '('. join(xmapargs, ',') . ')<CR>'
2014-01-13 14:29:09 -05:00
" Example:
2014-01-16 06:40:56 -05:00
" noremap <silent><Plug>(easymotion-f2) :<C-u>call EasyMotion#S(2,1,0)<CR>
2014-01-13 14:29:09 -05:00
" xnoremap <silent><Plug>(easymotion-f2) <Esc>:<C-u>call EasyMotion#S(2,1,0)<CR>
endfor
endfunction "}}}
2014-01-13 14:29:09 -05:00
" Find Motion: {{{
call s:motion_map_helper({
\ 'f' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 0},
\ 'F' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 1},
\ 's' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 2},
\ 'bd-f' : {'fnc' : 'S' , 'cnt' : 1, 'direction' : 2},
\ 't' : {'fnc' : 'T' , 'cnt' : 1, 'direction' : 0},
\ 'T' : {'fnc' : 'T' , 'cnt' : 1, 'direction' : 1},
\ 'bd-t' : {'fnc' : 'T' , 'cnt' : 1, 'direction' : 2},
\ 'fl' : {'fnc' : 'SL' , 'cnt' : 1, 'direction' : 0},
\ 'Fl' : {'fnc' : 'SL' , 'cnt' : 1, 'direction' : 1},
\ 'sl' : {'fnc' : 'SL' , 'cnt' : 1, 'direction' : 2},
\ 'bd-fl' : {'fnc' : 'SL' , 'cnt' : 1, 'direction' : 2},
\ 'tl' : {'fnc' : 'TL' , 'cnt' : 1, 'direction' : 0},
\ 'Tl' : {'fnc' : 'TL' , 'cnt' : 1, 'direction' : 1},
\ 'bd-tl' : {'fnc' : 'TL' , 'cnt' : 1, 'direction' : 2},
2014-01-13 14:29:09 -05:00
\
\ 'f2' : {'fnc' : 'S' , 'cnt' : 2, 'direction' : 0},
\ 'F2' : {'fnc' : 'S' , 'cnt' : 2, 'direction' : 1},
\ 's2' : {'fnc' : 'S' , 'cnt' : 2, 'direction' : 2},
\ 'bd-f2' : {'fnc' : 'S' , 'cnt' : 2, 'direction' : 2},
\ 't2' : {'fnc' : 'T' , 'cnt' : 2, 'direction' : 0},
\ 'T2' : {'fnc' : 'T' , 'cnt' : 2, 'direction' : 1},
\ 'bd-t2' : {'fnc' : 'T' , 'cnt' : 2, 'direction' : 2},
\ 'fl2' : {'fnc' : 'SL' , 'cnt' : 2, 'direction' : 0},
\ 'Fl2' : {'fnc' : 'SL' , 'cnt' : 2, 'direction' : 1},
\ 'sl2' : {'fnc' : 'SL' , 'cnt' : 2, 'direction' : 2},
\ 'bd-fl2' : {'fnc' : 'SL' , 'cnt' : 2, 'direction' : 2},
\ 'tl2' : {'fnc' : 'TL' , 'cnt' : 2, 'direction' : 0},
\ 'Tl2' : {'fnc' : 'TL' , 'cnt' : 2, 'direction' : 1},
\ 'bd-tl2' : {'fnc' : 'TL' , 'cnt' : 2, 'direction' : 2},
2014-01-13 14:29:09 -05:00
\
\ 'fn' : {'fnc' : 'S' , 'cnt' : -1, 'direction' : 0},
\ 'Fn' : {'fnc' : 'S' , 'cnt' : -1, 'direction' : 1},
\ 'sn' : {'fnc' : 'S' , 'cnt' : -1, 'direction' : 2},
\ 'bd-fn' : {'fnc' : 'S' , 'cnt' : -1, 'direction' : 2},
\ 'tn' : {'fnc' : 'T' , 'cnt' : -1, 'direction' : 0},
\ 'Tn' : {'fnc' : 'T' , 'cnt' : -1, 'direction' : 1},
\ 'bd-tn' : {'fnc' : 'T' , 'cnt' : -1, 'direction' : 2},
\ 'fln' : {'fnc' : 'SL' , 'cnt' : -1, 'direction' : 0},
\ 'Fln' : {'fnc' : 'SL' , 'cnt' : -1, 'direction' : 1},
\ 'sln' : {'fnc' : 'SL' , 'cnt' : -1, 'direction' : 2},
\ 'bd-fln' : {'fnc' : 'SL' , 'cnt' : -1, 'direction' : 2},
\ 'tln' : {'fnc' : 'TL' , 'cnt' : -1, 'direction' : 0},
\ 'Tln' : {'fnc' : 'TL' , 'cnt' : -1, 'direction' : 1},
\ 'bd-tln' : {'fnc' : 'TL' , 'cnt' : -1, 'direction' : 2},
\ })
nnoremap <silent> <Plug>(easymotion-overwin-f) :<C-u>call EasyMotion#OverwinF(1)<CR>
nnoremap <silent> <Plug>(easymotion-overwin-f2) :<C-u>call EasyMotion#OverwinF(2)<CR>
"}}}
" -- Word Motion {{{
call s:motion_map_helper({
\ 'w' : {'fnc' : 'WB' , 'direction' : 0},
\ 'b' : {'fnc' : 'WB' , 'direction' : 1},
\ 'bd-w' : {'fnc' : 'WB' , 'direction' : 2},
\ 'W' : {'fnc' : 'WBW', 'direction' : 0},
\ 'B' : {'fnc' : 'WBW', 'direction' : 1},
\ 'bd-W' : {'fnc' : 'WBW', 'direction' : 2},
\ 'iskeyword-w' : {'fnc' : 'WBK', 'direction' : 0},
\ 'iskeyword-b' : {'fnc' : 'WBK', 'direction' : 1},
\ 'iskeyword-bd-w' : {'fnc' : 'WBK', 'direction' : 2},
\
\ 'e' : {'fnc' : 'E' , 'direction' : 0},
\ 'ge' : {'fnc' : 'E' , 'direction' : 1},
\ 'bd-e' : {'fnc' : 'E' , 'direction' : 2},
\ 'E' : {'fnc' : 'EW' , 'direction' : 0},
\ 'gE' : {'fnc' : 'EW' , 'direction' : 1},
\ 'bd-E' : {'fnc' : 'EW' , 'direction' : 2},
\ 'iskeyword-e' : {'fnc' : 'EK' , 'direction' : 0},
\ 'iskeyword-ge' : {'fnc' : 'EK' , 'direction' : 1},
\ 'iskeyword-bd-e' : {'fnc' : 'EK' , 'direction' : 2},
\ })
"}}}
" -- JK Motion {{{
call s:motion_map_helper({
\ 'j' : {'fnc' : 'JK' , 'direction' : 0},
\ 'k' : {'fnc' : 'JK' , 'direction' : 1},
\ 'bd-jk' : {'fnc' : 'JK' , 'direction' : 2},
\ 'sol-j' : {'fnc' : 'Sol', 'direction' : 0},
\ 'sol-k' : {'fnc' : 'Sol', 'direction' : 1},
\ 'sol-bd-jk' : {'fnc' : 'Sol', 'direction' : 2},
\ 'eol-j' : {'fnc' : 'Eol', 'direction' : 0},
\ 'eol-k' : {'fnc' : 'Eol', 'direction' : 1},
\ 'eol-bd-jk' : {'fnc' : 'Eol', 'direction' : 2},
\ })
2014-01-16 06:40:56 -05:00
"}}}
" -- Search Motion {{{
call s:motion_map_helper({
\ 'n' : {'fnc' : 'Search', 'direction': 0, 'respect_direction': 0},
\ 'N' : {'fnc' : 'Search', 'direction': 1, 'respect_direction': 0},
\ 'bd-n' : {'fnc' : 'Search', 'direction': 2, 'respect_direction': 0},
\ 'vim-n' : {'fnc' : 'Search', 'direction': 0, 'respect_direction': 1},
\ 'vim-N' : {'fnc' : 'Search', 'direction': 1, 'respect_direction': 1},
\ })
2014-01-13 20:00:06 -05:00
"}}}
" -- Jump To Anywhere Motion {{{
call s:motion_map_helper({
\ 'jumptoanywhere' : {'fnc' : 'JumpToAnywhere', 'direction': 2},
\ })
"}}}
" -- Line Motion {{{
call s:motion_map_helper({
\ 'wl' : {'fnc' : 'WBL', 'direction': 0},
\ 'bl' : {'fnc' : 'WBL', 'direction': 1},
\ 'bd-wl' : {'fnc' : 'WBL', 'direction': 2},
\ 'el' : {'fnc' : 'EL' , 'direction': 0},
\ 'gel' : {'fnc' : 'EL' , 'direction': 1},
\ 'bd-el' : {'fnc' : 'EL' , 'direction': 2},
\ 'lineforward' : {'fnc' : 'LineAnywhere', 'direction': 0},
\ 'linebackward' : {'fnc' : 'LineAnywhere', 'direction': 1},
\ 'lineanywhere' : {'fnc' : 'LineAnywhere', 'direction': 2},
\ })
"}}}
" -- Next, Previous Motion {{{
noremap <silent><Plug>(easymotion-next)
\ :<C-u>call EasyMotion#NextPrevious(0,0)<CR>
xnoremap <silent><Plug>(easymotion-next)
\ :<C-u>call EasyMotion#NextPrevious(1,0)<CR>
noremap <silent><Plug>(easymotion-prev)
\ :<C-u>call EasyMotion#NextPrevious(0,1)<CR>
xnoremap <silent><Plug>(easymotion-prev)
\ :<C-u>call EasyMotion#NextPrevious(1,1)<CR>
"}}}
" -- Repeat Motion {{{
noremap <silent><Plug>(easymotion-repeat)
\ :<C-u>call EasyMotion#Repeat(0)<CR>
xnoremap <silent><Plug>(easymotion-repeat)
\ <Esc>:<C-u>call EasyMotion#Repeat(1)<CR>
noremap <silent><Plug>(easymotion-dotrepeat)
2014-06-30 11:02:28 -04:00
\ :<C-u>call EasyMotion#DotRepeat()<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>
2013-12-18 07:32:27 -05:00
" }}}
" == Default key mapping {{{
if g:EasyMotion_do_mapping == 1
" Prepare Prefix: {{{
if exists('g:EasyMotion_leader_key')
exec 'map ' . g:EasyMotion_leader_key . ' <Plug>(easymotion-prefix)'
else
if !hasmapto('<Plug>(easymotion-prefix)')
map <Leader><Leader> <Plug>(easymotion-prefix)
endif
endif
"}}}
2014-02-12 20:56:38 -05:00
function! s:default_mapping(motions, do_mapping) "{{{
for motion in a:motions
2014-02-12 20:56:38 -05:00
" Mapping {{{
if exists('g:EasyMotion_mapping_' . motion)
" Backward compatible mapping [deprecated]
silent exec 'map <silent> ' .
\ eval('g:EasyMotion_mapping_' . motion) . ' <Plug>(easymotion-' . motion . ')'
elseif a:do_mapping
\ && !hasmapto('<Plug>(easymotion-' . motion . ')')
\ && empty(maparg('<Plug>(easymotion-prefix)' . motion, 'nov'))
" Do mapping
silent exec 'map <silent> ' .
\'<Plug>(easymotion-prefix)' . motion . ' <Plug>(easymotion-' . motion . ')'
endif "}}}
endfor
endfunction "}}}
" Default Mapping:
call s:default_mapping(
\ ['f', 'F', 's', 't', 'T',
\ 'w', 'W', 'b', 'B', 'e', 'E', 'ge', 'gE',
\ 'j', 'k', 'n', 'N'], g:EasyMotion_do_mapping)
endif "}}}
" == CommandLine Mapping {{{
command! -nargs=*
2014-05-26 00:35:37 -04:00
\ EMCommandLineNoreMap
\ call EasyMotion#command_line#cnoremap([<f-args>])
command! -nargs=*
2014-05-26 00:35:37 -04:00
\ EMCommandLineMap
\ call EasyMotion#command_line#cmap([<f-args>])
command! -nargs=1
2014-05-26 00:35:37 -04:00
\ EMCommandLineUnMap
\ call EasyMotion#command_line#cunmap(<f-args>)
"}}}
" == Restore 'cpoptions' {{{
2013-12-18 07:32:27 -05:00
let &cpo = s:save_cpo
unlet s:save_cpo
2011-03-27 18:08:06 -04:00
" }}}
" vim: fdm=marker:et:ts=4:sw=4:sts=4