auto commit
This commit is contained in:
parent
376cc6b6d7
commit
d9661ac7da
@ -2,6 +2,7 @@
|
||||
1. Use one - two character key jump. Display two keys if one-character key is not enough, so you can see what two keys to type without waiting after pressing the first key.
|
||||
2. Added forward-backward search (bidirectional) search. You can jump forward or backward at the same time. `<Leader>s`. One useful trick is to map `nmap <SPACE> <leader>s` and `vmap <SPACE> <leader>s` to use space bar instead and save one keystroke!
|
||||
3. Added SelectLines function which allows you to select any range of lines using two consecutive easymotion calls. Default mappings are `cl, dl, vl, yl`. To yank a single line you can either type the same character(s) twice, or use '.' character. E.g. `vlb.` will select the line with character 'b'. Note: to promote good Vim habits, you should learn standard movement commands like `}}, vi(, va(, %, ][, ]], [(, etc.` before resorting to this function.
|
||||
4. (Experimental) Added SelectPhrase function which allows you to make selection between any two characters. Default mapping are `cp, dp, vp, yp`.
|
||||
|
||||
## Animated demonstration
|
||||
|
||||
|
@ -58,7 +58,7 @@
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! EasyMotion#SpecialMappings(motion) "{{{
|
||||
function! EasyMotion#SelectLinesMappings(motion) "{{{
|
||||
|
||||
if g:EasyMotion_special_select_line
|
||||
silent exec 'onoremap <silent> ' . a:motion . ' :call EasyMotion#SelectLines()<CR>'
|
||||
@ -66,6 +66,14 @@
|
||||
silent exec 'nnoremap <silent> y' . a:motion . ' :call EasyMotion#SelectLinesYank()<CR>'
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! EasyMotion#SelectPhraseMappings(motion) "{{{
|
||||
if g:EasyMotion_special_select_phrase
|
||||
silent exec 'onoremap <silent> ' . a:motion . ' :call EasyMotion#SelectPhrase()<CR>'
|
||||
silent exec 'nnoremap <silent> v' . a:motion . ' :call EasyMotion#SelectPhrase()<CR>'
|
||||
silent exec 'nnoremap <silent> y' . a:motion . ' :call EasyMotion#SelectPhraseYank()<CR>'
|
||||
endif
|
||||
endfunction "}}}
|
||||
" }}}
|
||||
" Motion functions {{{
|
||||
|
||||
@ -108,6 +116,42 @@
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! EasyMotion#SelectPhrase()
|
||||
let chars = s:GetSearchChar2(0)
|
||||
if empty(chars)
|
||||
return
|
||||
endif
|
||||
|
||||
let orig_pos = [line('.'), col('.')]
|
||||
|
||||
let re = '\C' . escape(chars[0], '.$^~') . '\|\C' . escape(chars[1], '.$^~')
|
||||
call s:EasyMotion(re, 2, '', '', 0, 0, 0, 0)
|
||||
if g:EasyMotion_cancelled
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
return ''
|
||||
else
|
||||
let pos1 = [line('.'), col('.')]
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
call s:EasyMotion(re, 2, '', '', 0, 0, 0, pos1)
|
||||
if g:EasyMotion_cancelled
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
return ''
|
||||
else
|
||||
normal! v
|
||||
keepjumps call cursor(pos1[0], pos1[1])
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! EasyMotion#SelectPhraseYank()
|
||||
let orig_pos = [line('.'), col('.')]
|
||||
|
||||
call EasyMotion#SelectPhrase()
|
||||
normal y
|
||||
keepjumps call cursor(orig_pos[0], orig_pos[1])
|
||||
endfunction
|
||||
|
||||
|
||||
function! EasyMotion#F(visualmode, direction) " {{{
|
||||
let char = s:GetSearchChar(a:visualmode)
|
||||
|
||||
@ -220,6 +264,32 @@
|
||||
|
||||
return nr2char(char)
|
||||
endfunction " }}}
|
||||
|
||||
function! s:GetSearchChar2(visualmode) " {{{
|
||||
|
||||
let chars = []
|
||||
for i in [1, 2]
|
||||
redraw
|
||||
|
||||
call s:Prompt('Search for character ' . i)
|
||||
let char = s:GetChar()
|
||||
|
||||
" Check that we have an input char
|
||||
if empty(char)
|
||||
" Restore selection
|
||||
if ! empty(a:visualmode)
|
||||
silent exec 'normal! gv'
|
||||
endif
|
||||
|
||||
return ''
|
||||
endif
|
||||
call add(chars, char)
|
||||
endfor
|
||||
|
||||
return chars
|
||||
endfunction " }}}
|
||||
|
||||
|
||||
function! s:GetSearchChar(visualmode) " {{{
|
||||
call s:Prompt('Search for character')
|
||||
|
||||
@ -607,6 +677,8 @@
|
||||
" of the line
|
||||
let fixed_column = a:0 >= 3 ? a:3 : 0
|
||||
|
||||
let hlchar = a:0 >= 4 ? a:4 : 0
|
||||
|
||||
let orig_pos = [line('.'), col('.')]
|
||||
let targets = []
|
||||
|
||||
@ -638,7 +710,9 @@
|
||||
continue
|
||||
endif
|
||||
|
||||
call add(targets, pos)
|
||||
if empty(hlchar) || pos != hlchar
|
||||
call add(targets, pos)
|
||||
endif
|
||||
endwhile
|
||||
|
||||
if a:direction == 2
|
||||
@ -654,7 +728,9 @@
|
||||
continue
|
||||
endif
|
||||
|
||||
call add(targets2, pos)
|
||||
if empty(hlchar) || pos != hlchar
|
||||
call add(targets2, pos)
|
||||
endif
|
||||
endwhile
|
||||
let t1 = 0
|
||||
let t2 = 0
|
||||
@ -703,6 +779,9 @@
|
||||
if hlcurrent != 0
|
||||
let shade_hl_line_id = matchadd(g:EasyMotion_hl_line_group_shade, '\%'. hlcurrent .'l.*', 1)
|
||||
endif
|
||||
if !empty(hlchar)
|
||||
let shade_hl_line_id = matchadd(g:EasyMotion_hl_line_group_shade, '\%'. hlchar[0] .'l\%' . hlchar[1] .'c' , 1)
|
||||
endif
|
||||
" }}}
|
||||
|
||||
" Prompt user for target group/character
|
||||
@ -761,7 +840,7 @@
|
||||
if g:EasyMotion_do_shade && exists('shade_hl_id') && (!fixed_column)
|
||||
call matchdelete(shade_hl_id)
|
||||
endif
|
||||
if hlcurrent && exists('shade_hl_line_id')
|
||||
if (hlcurrent || !empty(hlchar)) && exists('shade_hl_line_id')
|
||||
call matchdelete(shade_hl_line_id)
|
||||
endif
|
||||
" }}}
|
||||
|
@ -13,12 +13,13 @@
|
||||
" Default configuration {{{
|
||||
" Default options {{{
|
||||
call EasyMotion#InitOptions({
|
||||
\ 'leader_key' : '<Leader><Leader>'
|
||||
\ , 'keys' : 'abcdeghiklmnopqrstuvwxyzfj'
|
||||
\ , 'do_shade' : 1
|
||||
\ , 'do_mapping' : 1
|
||||
\ , 'special_select_line' : 1
|
||||
\ , 'grouping' : 1
|
||||
\ 'leader_key' : '<Leader><Leader>'
|
||||
\ , 'keys' : 'abcdeghiklmnopqrstuvwxyzfj'
|
||||
\ , 'do_shade' : 1
|
||||
\ , 'do_mapping' : 1
|
||||
\ , 'special_select_line' : 1
|
||||
\ , 'special_select_phrase' : 1
|
||||
\ , 'grouping' : 1
|
||||
\
|
||||
\ , 'hl_group_target' : 'EasyMotionTarget'
|
||||
\ , 'hl2_first_group_target' : 'EasyMotionTarget2First'
|
||||
@ -97,9 +98,9 @@
|
||||
\ , 'N' : { 'name': 'Search' , 'dir': 1 }
|
||||
\ })
|
||||
" }}}
|
||||
" Special mapping for SelectLine function {{{
|
||||
call EasyMotion#SpecialMappings('l')
|
||||
"
|
||||
" Special mapping for other functions {{{
|
||||
call EasyMotion#SelectLinesMappings('l')
|
||||
call EasyMotion#SelectPhraseMappings('p')
|
||||
" }}}
|
||||
" }}}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user