" Vim plugin to provide multiline analogs to t & f if !exists('g:supert_provide_bindings') let g:supert_provide_bindings = 1 endif let s:last = [] let s:insert_char = '' function! s:getchar() let s:insert_char = nr2char(getchar()) endfunction function! s:do_search(type, vis) abort if a:type == ';' call s:do_last(0, a:vis) elseif a:type == ',' call s:do_last(1, a:vis) else call s:do_search_ch(a:type, a:vis, s:insert_char) endif endfunction function! s:do_last(inv, vis) abort if len(s:last) < 2 return return endif le] type = s:last[0] let ch = s:last[1] if a:inv if type =~ '[a-z]' let type = toupper(type) else let type = tolower(type) endif endif return s:do_search_ch(type, a:vis, ch) endfunction function! s:do_search_ch(type, vis, ch) let s:last = [a:type, a:ch] let flags = 'W' let pattern = '' if a:type =~ '[A-Z]' let flags .= 'b' endif let pattern = a:ch if a:type == 't' let pattern = '\zs\_.\ze' . pattern elseif a:type == 'T' let pattern = pattern . '\zs\_.\ze' endif if a:vis != '' exec "normal! v" endif let i = 0 while i < v:count1 call search(pattern, flags) let i += 1 endwhile endfunction " Prepares the operation by reading a character from the user, escapes the " current operator-pending mode and then crafts a new command using the private- " scoped (strf-post) command. function! s:prepare_operation(t, op) let s:operator = a:op let s:type = a:t let s:insert_char = nr2char(getchar()) call feedkeys("\") call feedkeys(printf("%s\(srtf-post)", s:operator)) endfunction " Include the bindings if the user wast to include them. if g:supert_provide_bindings onoremap Zt (srtf-to) onoremap Zf (srtf-fo) onoremap ZT (srtf-To) onoremap ZF (srtf-Fo) nnoremap Zt (srtf-t) nnoremap Zf (srtf-f) nnoremap ZT (srtf-T) nnoremap ZF (srtf-F) vnoremap Zt (srtf-tv) vnoremap Zf (srtf-fv) vnoremap ZT (srtf-Tv) vnoremap ZF (srtf-Fv) endif " test? vnoremap (srtf-tv) call getchar()call do_search('t', '') vnoremap (srtf-fv) call getchar()call do_search('f', '') vnoremap (srtf-Tv) call getchar()call do_search('T', '') vnoremap (srtf-Fv) call getchar()call do_search('F', '') nnoremap (srtf-t) call getchar()call do_search('t', '') nnoremap (srtf-f) call getchar()call do_search('f', '') nnoremap (srtf-T) call getchar()call do_search('T', '') nnoremap (srtf-F) call getchar()call do_search('F', '') onoremap (srtf-to) call prepare_operation('t', v:operator) onoremap (srtf-fo) call prepare_operation('f', v:operator) onoremap (srtf-To) call prepare_operation('T', v:operator) onoremap (srtf-Fo) call prepare_operation('F', v:operator) " is this a question? Or is that? onoremap (srtf-post) call do_search_postchar('v') function! s:do_search_postchar(vis) abort echom printf("do_search(%s, %s)", s:type, a:vis) call s:do_search(s:type, a:vis) endfunction