diff --git a/autoload/EasyMotion.vim b/autoload/EasyMotion.vim index fe93520..1f11f57 100644 --- a/autoload/EasyMotion.vim +++ b/autoload/EasyMotion.vim @@ -45,6 +45,7 @@ function! EasyMotion#reset() let s:flag = { \ 'within_line' : 0, \ 'dot_repeat' : 0, + \ 'regexp' : 0, \ } let s:current = { \ 'is_operator' : 0, @@ -321,8 +322,8 @@ function! EasyMotion#DotRepeat(visualmode) " {{{ let is_exclusive = s:previous.is_exclusive let s:current.is_operator = 1 let s:flag.within_line = s:previous.line_flag + let s:flag.dot_repeat = 1 for cnt in range(v:count1) - let s:flag.dot_repeat = 1 silent call s:EasyMotion(re, direction, 0, is_exclusive) endfor endfunction " }}} @@ -456,6 +457,7 @@ endfunction " }}} function! s:findMotion(num_strokes) "{{{ " Find Motion: S,F,T let s:current.is_operator = mode(1) ==# 'no' ? 1: 0 + let s:flag.regexp = a:num_strokes == -1 ? 1 : 0 let s:previous['input'] = get(s:previous, 'input', '') let input = EasyMotion#command_line#GetInput(a:num_strokes, s:previous.input) @@ -476,7 +478,7 @@ function! s:findMotion(num_strokes) "{{{ return re endfunction "}}} function! s:convertRegep(input) "{{{ - let re = escape(a:input, '.$^~\[]') + let re = s:should_use_regexp() ? a:input : escape(a:input, '.$^~\[]') if s:should_use_migemo(a:input) let re = s:convertMigemo(re) @@ -525,6 +527,9 @@ function! s:convertSmartcase(re, char) "{{{ return '\C' . re endif endfunction "}}} +function! s:should_use_regexp() "{{{ + return g:EasyMotion_use_regexp == 1 && s:flag.regexp == 1 +endfunction "}}} function! s:should_use_migemo(char) "{{{ if ! g:EasyMotion_use_migemo || match(a:char, '\A') != -1 return 0 diff --git a/plugin/EasyMotion.vim b/plugin/EasyMotion.vim index d3f72e6..df09b51 100644 --- a/plugin/EasyMotion.vim +++ b/plugin/EasyMotion.vim @@ -31,6 +31,7 @@ let g:EasyMotion_smartcase = get(g: , 'EasyMotion_smartcase' , 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_use_regexp = get(g: , 'EasyMotion_use_regexp' , 0) let g:EasyMotion_enter_jump_first = get(g: , 'EasyMotion_enter_jump_first' , 0) let g:EasyMotion_show_prompt = get(g: , 'EasyMotion_show_prompt' , 1) let g:EasyMotion_prompt = diff --git a/t/easymotion_spec.vim b/t/easymotion_spec.vim index 9b2bfcb..f123d2a 100644 --- a/t/easymotion_spec.vim +++ b/t/easymotion_spec.vim @@ -1091,5 +1091,44 @@ describe 'EasyMotion is jump motion' end "}}} +" Regexp {{{ +describe 'EasyMotion regexp' + before + new + let g:EasyMotion_keys = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' + let g:EasyMotion_use_regexp = 1 + map s (easymotion-sn) + call EasyMotion#init() + call AddLine('poge1 2huga 3hiyo 4poyo') + " 12345678901234567890123 + end + + after + let g:EasyMotion_use_regexp = 0 + close! + end + + " could jump back to previous location {{{ + it 'provide regexp motion' + normal! 0 + let l = line('.') + Expect CursorPos() == [l,1,'p'] + exe "normal s\\d\a" + Expect CursorPos() == [l,5,'1'] + + normal! 0 + Expect CursorPos() == [l,1,'p'] + exe "normal s\\d\c" + Expect CursorPos() == [l,13,'3'] + + exe "normal s\$\a" + Expect CursorPos() == [l,23,'o'] + + exe "normal s\^\b" + Expect CursorPos() == [l,1,'p'] + end + "}}} +end +"}}} " vim: fdm=marker:et:ts=4:sw=4:sts=4