diff --git a/autoload/EasyMotion.vim b/autoload/EasyMotion.vim index 677e190..49ed243 100644 --- a/autoload/EasyMotion.vim +++ b/autoload/EasyMotion.vim @@ -48,35 +48,15 @@ function! EasyMotion#reset() endfunction "}}} " == Motion functions {{{ " -- Find Motion ------------------------- -function! EasyMotion#F(visualmode, direction) " {{{ - let char = s:GetSearchChar(a:visualmode) +function! EasyMotion#S(num_strokes, mode, direction) " {{{ + let visualmode = match('\v([Vv])|(C-v)', a:mode) > 0 ? 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#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) + let input = s:GetInput(a:num_strokes) " Check that we have an input char if empty(input) " Restore selection - if ! empty(a:visualmode) + if ! empty(visualmode) silent exec 'normal! gv' endif return @@ -84,16 +64,22 @@ function! EasyMotion#S2(visualmode, direction) " {{{ 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 " }}} -function! EasyMotion#T(visualmode, direction) " {{{ - let char = s:GetSearchChar(a:visualmode) +function! EasyMotion#T(num_strokes, mode, direction) " {{{ + 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 endif - let re = s:findMotion(char) + let re = s:findMotion(input) if a:direction == 1 " backward @@ -103,7 +89,7 @@ function! EasyMotion#T(visualmode, direction) " {{{ let re = '.\ze' . re endif - call s:EasyMotion(re, a:direction, a:visualmode ? visualmode() : '', mode(1)) + call s:EasyMotion(re, a:direction, visualmode, a:mode) endfunction " }}} " -- Word Motion ------------------------- function! EasyMotion#WB(visualmode, direction) " {{{ diff --git a/autoload/EasyMotion/helper.vim b/autoload/EasyMotion/helper.vim new file mode 100644 index 0000000..b1db92e --- /dev/null +++ b/autoload/EasyMotion/helper.vim @@ -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" : mode(a:flag) +endfunction "}}} + +" Restore 'cpoptions' {{{ +let &cpo = s:save_cpo +unlet s:save_cpo +" }}} diff --git a/plugin/EasyMotion.vim b/plugin/EasyMotion.vim index 6108ffe..4bcd261 100644 --- a/plugin/EasyMotion.vim +++ b/plugin/EasyMotion.vim @@ -106,10 +106,7 @@ if g:EasyMotion_do_mapping == 1 endif "}}} call EasyMotion#init#InitMappings({ - \ 'f' : { 'name': 'F' , 'dir': 0 } - \ , 'F' : { 'name': 'F' , 'dir': 1 } - \ , 's' : { 'name': 'S' , 'dir': 2 } - \ , 'S' : { 'name': 'WB' , 'dir': 2 } + \ 'S' : { 'name': 'WB' , 'dir': 2 } \ , 't' : { 'name': 'T' , 'dir': 0 } \ , 'T' : { 'name': 'T' , 'dir': 1 } \ , 'w' : { 'name': 'WB' , 'dir': 0 } @@ -163,11 +160,24 @@ call EasyMotion#init#InitMappings({ \ , 'bd-el' : { 'name' : 'EL' , 'dir' : 2 } \ \ , 'repeat' : { 'name': 'Repeat' , 'dir': 0 } - \ - \ , 's2' : { 'name': 'S2' , 'dir': 2 } \ }, 0) " Prepare but don't map by default. " }}} +noremap (easymotion-s) + \ ':call EasyMotion#S(1, "' . EasyMotion#helper#mode(1) . '" ,2)' +noremap (easymotion-s2) + \ ':call EasyMotion#S(3, "' . EasyMotion#helper#mode(1) . '" ,2)' + +noremap (easymotion-f) + \ ':call EasyMotion#S(1, "' . EasyMotion#helper#mode(1) . '" ,0)' +noremap (easymotion-F) + \ ':call EasyMotion#S(1, "' . EasyMotion#helper#mode(1) . '" ,1)' + +noremap (easymotion-t) + \ ':call EasyMotion#T(1, "' . EasyMotion#helper#mode(1) . '" ,0)' +noremap (easymotion-T) + \ ':call EasyMotion#T(1, "' . EasyMotion#helper#mode(1) . '" ,1)' + " }}} " == Restore 'cpoptions' {{{ let &cpo = s:save_cpo