Perform refactoring plug/easymotion.vim and init.vim

Flatten indent and Delete InitOptions function
This commit is contained in:
haya14busa 2014-01-10 23:08:03 +09:00
parent 7568f2f561
commit fb81281dc8
2 changed files with 164 additions and 161 deletions

View File

@ -3,14 +3,6 @@ let s:save_cpo = &cpo
set cpo&vim set cpo&vim
" }}} " }}}
function! EasyMotion#init#InitOptions(options) " {{{
for [key, value] in items(a:options)
if ! exists('g:EasyMotion_' . key)
exec 'let g:EasyMotion_' . key . ' = ' . string(value)
endif
endfor
endfunction " }}}
function! EasyMotion#init#InitHL(group, colors) " {{{ function! EasyMotion#init#InitHL(group, colors) " {{{
let group_default = a:group . 'Default' let group_default = a:group . 'Default'
@ -44,14 +36,14 @@ endfunction " }}}
function! EasyMotion#init#InitMappings(motions, do_mapping) "{{{ function! EasyMotion#init#InitMappings(motions, do_mapping) "{{{
for [motion, fn] in items(a:motions) for [motion, fn] in items(a:motions)
" Prepare <Plug> mapping {{{ " Prepare <Plug> mapping {{{
silent exec 'nnoremap <silent> silent exec 'nnoremap <silent>' .
\ <Plug>(easymotion-' . motion . ') \ '<Plug>(easymotion-' . motion . ')
\ :call EasyMotion#' . fn.name . '(0, ' . fn.dir . ')<CR>' \ :call EasyMotion#' . fn.name . '(0, ' . fn.dir . ')<CR>'
silent exec 'onoremap <silent> silent exec 'onoremap <silent>' .
\ <Plug>(easymotion-' . motion . ') \ '<Plug>(easymotion-' . motion . ')
\ :call EasyMotion#' . fn.name . '(0, ' . fn.dir . ')<CR>' \ :call EasyMotion#' . fn.name . '(0, ' . fn.dir . ')<CR>'
silent exec 'vnoremap <silent> silent exec 'vnoremap <silent>' .
\ <Plug>(easymotion-' . motion . ') \ '<Plug>(easymotion-' . motion . ')
\ :<C-u>call EasyMotion#' . fn.name . '(1, ' . fn.dir . ')<CR>' \ :<C-u>call EasyMotion#' . fn.name . '(1, ' . fn.dir . ')<CR>'
"}}} "}}}
@ -74,14 +66,14 @@ endfunction "}}}
function! EasyMotion#init#InitSpecialMappings(motions, do_mapping) "{{{ function! EasyMotion#init#InitSpecialMappings(motions, do_mapping) "{{{
for [motion, fn] in items(a:motions) for [motion, fn] in items(a:motions)
silent exec 'onoremap <silent> silent exec 'onoremap <silent>' .
\ <Plug>(easymotion-special-' . motion . ') :call EasyMotion#' . fn.name . '()<CR>' \ '<Plug>(easymotion-special-' . motion . ') :call EasyMotion#' . fn.name . '()<CR>'
silent exec 'vnoremap <silent> silent exec 'vnoremap <silent>' .
\ <Plug>(easymotion-special-' . motion . ') :<C-u>call EasyMotion#' . fn.name . '()<CR>' \ '<Plug>(easymotion-special-' . motion . ') :<C-u>call EasyMotion#' . fn.name . '()<CR>'
silent exec 'nnoremap <silent> silent exec 'nnoremap <silent>' .
\ y<Plug>(easymotion-special-' . motion . ') :call EasyMotion#' . fn.name . 'Yank()<CR>' \ 'y<Plug>(easymotion-special-' . motion . ') :call EasyMotion#' . fn.name . 'Yank()<CR>'
silent exec 'nnoremap <silent> silent exec 'nnoremap <silent>' .
\ d<Plug>(easymotion-special-' . motion . ') :call EasyMotion#' . fn.name . 'Delete()<CR>' \ 'd<Plug>(easymotion-special-' . motion . ') :call EasyMotion#' . fn.name . 'Delete()<CR>'
" Do mapping {{{ " Do mapping {{{
if a:do_mapping if a:do_mapping

View File

@ -3,49 +3,45 @@
" Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com> " Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com>
" Source repository: https://github.com/Lokaltog/vim-easymotion " Source repository: https://github.com/Lokaltog/vim-easymotion
" Script initialization {{{ " == Script initialization {{{
if exists('g:EasyMotion_loaded') || &compatible || version < 702 if exists('g:EasyMotion_loaded') || &compatible || version < 702
finish finish
endif endif
let g:EasyMotion_loaded = 1 let g:EasyMotion_loaded = 1
" }}} " }}}
" Saving 'cpoptions' {{{ " == Saving 'cpoptions' {{{
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
" }}} " }}}
" Default configuration {{{ " == Default configuration {{{
" Default options {{{ " -- Option ------------------------------ {{{
let g:EasyMotion_keys = get(g:,
\ 'EasyMotion_keys', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
let g:EasyMotion_do_mapping = get(g: , 'EasyMotion_do_mapping' , 1) let g:EasyMotion_do_mapping = get(g: , 'EasyMotion_do_mapping' , 1)
if g:EasyMotion_do_mapping == 1 let g:EasyMotion_do_special_mapping = get(g: , 'EasyMotion_do_special_mapping' , 0)
if exists('g:EasyMotion_leader_key') let g:EasyMotion_do_shade = get(g: , 'EasyMotion_do_shade' , 1)
exec 'map ' . g:EasyMotion_leader_key . ' <Plug>(easymotion-prefix)' let g:EasyMotion_grouping = get(g: , 'EasyMotion_grouping' , 1)
else let g:EasyMotion_startofline = get(g: , 'EasyMotion_startofline' , 1)
if !hasmapto('<Plug>(easymotion-prefix)') let g:EasyMotion_smartcase = get(g: , 'EasyMotion_smartcase' , 0)
map <Leader><Leader> <Plug>(easymotion-prefix) let g:EasyMotion_skipfoldedline = get(g: , 'EasyMotion_skipfoldedline' , 1)
endif let g:EasyMotion_use_migemo = get(g: , 'EasyMotion_use_migemo' , 0)
endif let g:EasyMotion_use_upper = get(g: , 'EasyMotion_use_upper' , 0)
endif let g:EasyMotion_enter_jump_first = get(g: , 'EasyMotion_enter_jump_first' , 0)
call EasyMotion#init#InitOptions({
\ 'keys' : 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
\ , 'do_shade' : 1
\ , 'do_special_mapping' : 0
\ , 'grouping' : 1
\ , 'startofline' : 1
\ , 'smartcase' : 0
\ , 'skipfoldedline' : 1
\ , 'use_migemo' : 0
\ , 'use_upper' : 0
\ , 'enter_jump_first' : 0
\
\ , 'hl_group_target' : 'EasyMotionTarget'
\ , 'hl2_first_group_target' : 'EasyMotionTarget2First'
\ , 'hl2_second_group_target' : 'EasyMotionTarget2Second'
\ , 'hl_group_shade' : 'EasyMotionShade'
\ , 'hl_line_group_shade' : 'EasyMotionShadeLine'
\ })
"}}} "}}}
" Default highlighting {{{
" -- Default highlighting ---------------- {{{
let g:EasyMotion_hl_group_target = get(g:,
\ 'EasyMotion_hl_group_target', 'EasyMotionTarget')
let g:EasyMotion_hl2_first_group_target = get(g:,
\ 'EasyMotion_hl2_first_group_target', 'EasyMotionTarget2First')
let g:EasyMotion_hl2_second_group_target = get(g:,
\ 'EasyMotion_hl2_second_group_target', 'EasyMotionTarget2Second')
let g:EasyMotion_hl_group_shade = get(g:,
\ 'EasyMotion_hl_group_shade', 'EasyMotionShade')
let g:EasyMotion_hl_line_group_shade = get(g:,
\ 'EasyMotion_hl_line_group_shade', 'EasyMotionShadeLine')
let s:target_hl_defaults = { let s:target_hl_defaults = {
\ 'gui' : ['NONE', '#ff0000' , 'bold'] \ 'gui' : ['NONE', '#ff0000' , 'bold']
\ , 'cterm256': ['NONE', '196' , 'bold'] \ , 'cterm256': ['NONE', '196' , 'bold']
@ -94,7 +90,19 @@ set cpo&vim
augroup end augroup end
" }}} " }}}
" }}} " }}}
" Default key mapping {{{
" -- Default key mapping ----------------- {{{
" Prepare prefix {{{
if g:EasyMotion_do_mapping == 1
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
endif "}}}
call EasyMotion#init#InitMappings({ call EasyMotion#init#InitMappings({
\ 'f' : { 'name': 'F' , 'dir': 0 } \ 'f' : { 'name': 'F' , 'dir': 0 }
\ , 'F' : { 'name': 'F' , 'dir': 1 } \ , 'F' : { 'name': 'F' , 'dir': 1 }
@ -116,13 +124,15 @@ set cpo&vim
\ , 'N' : { 'name': 'Search' , 'dir': 1 } \ , 'N' : { 'name': 'Search' , 'dir': 1 }
\ }, g:EasyMotion_do_mapping) \ }, g:EasyMotion_do_mapping)
" }}} " }}}
" Special mapping for other functions {{{
" -- Special mapping for other functions - {{{
call EasyMotion#init#InitSpecialMappings({ call EasyMotion#init#InitSpecialMappings({
\ 'l' : { 'name': 'SelectLines'} \ 'l' : { 'name': 'SelectLines'}
\ , 'p' : { 'name': 'SelectPhrase'} \ , 'p' : { 'name': 'SelectPhrase'}
\ }, g:EasyMotion_do_special_mapping) \ }, g:EasyMotion_do_special_mapping)
" }}} " }}}
" Prepare more key mapping {{{
" -- Prepare more key mapping ------------ {{{
" Note: bd is short for bidirectional " Note: bd is short for bidirectional
" l is short for (within) line " l is short for (within) line
call EasyMotion#init#InitMappings({ call EasyMotion#init#InitMappings({
@ -153,8 +163,9 @@ set cpo&vim
\ , 'repeat' : { 'name': 'Repeat' , 'dir': 0 } \ , 'repeat' : { 'name': 'Repeat' , 'dir': 0 }
\ }, 0) " Prepare <Plug> but don't map by default. \ }, 0) " Prepare <Plug> but don't map by default.
" }}} " }}}
" }}} " }}}
" Restore 'cpoptions' {{{ " == Restore 'cpoptions' {{{
let &cpo = s:save_cpo let &cpo = s:save_cpo
unlet s:save_cpo unlet s:save_cpo
" }}} " }}}