Refactoring of find motion for multi key strokes
This commit is contained in:
parent
14d4792180
commit
6c656b1f17
@ -48,35 +48,15 @@ function! EasyMotion#reset()
|
|||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
" == Motion functions {{{
|
" == Motion functions {{{
|
||||||
" -- Find Motion -------------------------
|
" -- Find Motion -------------------------
|
||||||
function! EasyMotion#F(visualmode, direction) " {{{
|
function! EasyMotion#S(num_strokes, mode, direction) " {{{
|
||||||
let char = s:GetSearchChar(a:visualmode)
|
let visualmode = match('\v([Vv])|(C-v)', a:mode) > 0 ? visualmode() : ''
|
||||||
|
|
||||||
if empty(char)
|
let input = s:GetInput(a:num_strokes)
|
||||||
return
|
|
||||||
endif
|
|
||||||
|
|
||||||
let re = s:findMotion(char)
|
|
||||||
|
|
||||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
|
||||||
endfunction " }}}
|
|
||||||
function! EasyMotion#S(visualmode, direction) " {{{
|
|
||||||
let char = s:GetSearchChar(a:visualmode)
|
|
||||||
|
|
||||||
if empty(char)
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
|
|
||||||
let re = s:findMotion(char)
|
|
||||||
|
|
||||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
|
||||||
endfunction " }}}
|
|
||||||
function! EasyMotion#S2(visualmode, direction) " {{{
|
|
||||||
let input = s:GetInput(2)
|
|
||||||
|
|
||||||
" Check that we have an input char
|
" Check that we have an input char
|
||||||
if empty(input)
|
if empty(input)
|
||||||
" Restore selection
|
" Restore selection
|
||||||
if ! empty(a:visualmode)
|
if ! empty(visualmode)
|
||||||
silent exec 'normal! gv'
|
silent exec 'normal! gv'
|
||||||
endif
|
endif
|
||||||
return
|
return
|
||||||
@ -84,16 +64,22 @@ function! EasyMotion#S2(visualmode, direction) " {{{
|
|||||||
|
|
||||||
let re = s:findMotion(input)
|
let re = s:findMotion(input)
|
||||||
|
|
||||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
call s:EasyMotion(re, a:direction, visualmode, a:mode)
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
function! EasyMotion#T(visualmode, direction) " {{{
|
function! EasyMotion#T(num_strokes, mode, direction) " {{{
|
||||||
let char = s:GetSearchChar(a:visualmode)
|
let visualmode = match('\v([Vv])|(C-v)', a:mode) > 0 ? visualmode() : ''
|
||||||
|
let input = s:GetInput(a:num_strokes)
|
||||||
|
|
||||||
if empty(char)
|
" Check that we have an input char
|
||||||
|
if empty(input)
|
||||||
|
" Restore selection
|
||||||
|
if ! empty(visualmode)
|
||||||
|
silent exec 'normal! gv'
|
||||||
|
endif
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let re = s:findMotion(char)
|
let re = s:findMotion(input)
|
||||||
|
|
||||||
if a:direction == 1
|
if a:direction == 1
|
||||||
" backward
|
" backward
|
||||||
@ -103,7 +89,7 @@ function! EasyMotion#T(visualmode, direction) " {{{
|
|||||||
let re = '.\ze' . re
|
let re = '.\ze' . re
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1))
|
call s:EasyMotion(re, a:direction, visualmode, a:mode)
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
" -- Word Motion -------------------------
|
" -- Word Motion -------------------------
|
||||||
function! EasyMotion#WB(visualmode, direction) " {{{
|
function! EasyMotion#WB(visualmode, direction) " {{{
|
||||||
|
39
autoload/EasyMotion/helper.vim
Normal file
39
autoload/EasyMotion/helper.vim
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
"=============================================================================
|
||||||
|
" FILE: autoload/EasyMotion/helper.vim
|
||||||
|
" AUTHOR: haya14busa
|
||||||
|
" Last Change: 12 Jan 2014.
|
||||||
|
" License: MIT license {{{
|
||||||
|
" Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
" a copy of this software and associated documentation files (the
|
||||||
|
" "Software"), to deal in the Software without restriction, including
|
||||||
|
" without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
" distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
" permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
" the following conditions:
|
||||||
|
"
|
||||||
|
" The above copyright notice and this permission notice shall be included
|
||||||
|
" in all copies or substantial portions of the Software.
|
||||||
|
"
|
||||||
|
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
" }}}
|
||||||
|
"=============================================================================
|
||||||
|
scriptencoding utf-8
|
||||||
|
" Saving 'cpoptions' {{{
|
||||||
|
let s:save_cpo = &cpo
|
||||||
|
set cpo&vim
|
||||||
|
" }}}
|
||||||
|
|
||||||
|
function! EasyMotion#helper#mode(flag) "{{{
|
||||||
|
return mode(a:flag) == "\<C-v>" ? "C-v" : mode(a:flag)
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
|
" Restore 'cpoptions' {{{
|
||||||
|
let &cpo = s:save_cpo
|
||||||
|
unlet s:save_cpo
|
||||||
|
" }}}
|
@ -106,10 +106,7 @@ if g:EasyMotion_do_mapping == 1
|
|||||||
endif "}}}
|
endif "}}}
|
||||||
|
|
||||||
call EasyMotion#init#InitMappings({
|
call EasyMotion#init#InitMappings({
|
||||||
\ 'f' : { 'name': 'F' , 'dir': 0 }
|
\ 'S' : { 'name': 'WB' , 'dir': 2 }
|
||||||
\ , 'F' : { 'name': 'F' , 'dir': 1 }
|
|
||||||
\ , 's' : { 'name': 'S' , 'dir': 2 }
|
|
||||||
\ , 'S' : { 'name': 'WB' , 'dir': 2 }
|
|
||||||
\ , 't' : { 'name': 'T' , 'dir': 0 }
|
\ , 't' : { 'name': 'T' , 'dir': 0 }
|
||||||
\ , 'T' : { 'name': 'T' , 'dir': 1 }
|
\ , 'T' : { 'name': 'T' , 'dir': 1 }
|
||||||
\ , 'w' : { 'name': 'WB' , 'dir': 0 }
|
\ , 'w' : { 'name': 'WB' , 'dir': 0 }
|
||||||
@ -163,11 +160,24 @@ call EasyMotion#init#InitMappings({
|
|||||||
\ , 'bd-el' : { 'name' : 'EL' , 'dir' : 2 }
|
\ , 'bd-el' : { 'name' : 'EL' , 'dir' : 2 }
|
||||||
\
|
\
|
||||||
\ , 'repeat' : { 'name': 'Repeat' , 'dir': 0 }
|
\ , 'repeat' : { 'name': 'Repeat' , 'dir': 0 }
|
||||||
\
|
|
||||||
\ , 's2' : { 'name': 'S2' , 'dir': 2 }
|
|
||||||
\ }, 0) " Prepare <Plug> but don't map by default.
|
\ }, 0) " Prepare <Plug> but don't map by default.
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
|
noremap <silent><expr><Plug>(easymotion-s)
|
||||||
|
\ ':<C-u>call EasyMotion#S(1, "' . EasyMotion#helper#mode(1) . '" ,2)<CR>'
|
||||||
|
noremap <silent><expr><Plug>(easymotion-s2)
|
||||||
|
\ ':<C-u>call EasyMotion#S(3, "' . EasyMotion#helper#mode(1) . '" ,2)<CR>'
|
||||||
|
|
||||||
|
noremap <silent><expr><Plug>(easymotion-f)
|
||||||
|
\ ':<C-u>call EasyMotion#S(1, "' . EasyMotion#helper#mode(1) . '" ,0)<CR>'
|
||||||
|
noremap <silent><expr><Plug>(easymotion-F)
|
||||||
|
\ ':<C-u>call EasyMotion#S(1, "' . EasyMotion#helper#mode(1) . '" ,1)<CR>'
|
||||||
|
|
||||||
|
noremap <silent><expr><Plug>(easymotion-t)
|
||||||
|
\ ':<C-u>call EasyMotion#T(1, "' . EasyMotion#helper#mode(1) . '" ,0)<CR>'
|
||||||
|
noremap <silent><expr><Plug>(easymotion-T)
|
||||||
|
\ ':<C-u>call EasyMotion#T(1, "' . EasyMotion#helper#mode(1) . '" ,1)<CR>'
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
" == Restore 'cpoptions' {{{
|
" == Restore 'cpoptions' {{{
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user