aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugin/supert.vim108
1 files changed, 59 insertions, 49 deletions
diff --git a/plugin/supert.vim b/plugin/supert.vim
index f4a8e85..752d70a 100644
--- a/plugin/supert.vim
+++ b/plugin/supert.vim
@@ -6,13 +6,9 @@ endif
let s:last = []
-let s:last_char = ''
+let s:insert_char = ''
function! s:getchar()
- echom "Is not repeating? " . string(! exists('v:repeating') || ! v:repeating)
- if ! exists('v:repeating') || ! v:repeating
- let s:last_char = nr2char(getchar())
- endif
- return s:last_char
+ let s:insert_char = nr2char(getchar())
endfunction
function! s:do_search(type, vis) abort
@@ -21,16 +17,18 @@ function! s:do_search(type, vis) abort
elseif a:type == ','
call s:do_last(1, a:vis)
else
- call s:do_search_ch(a:type, a:vis, s:getchar())
+ 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
- let type = s:last[0]
+ le] type = s:last[0]
let ch = s:last[1]
if a:inv
@@ -62,6 +60,10 @@ function! s:do_search_ch(type, vis, ch)
let pattern = pattern . '\zs\_.\ze'
endif
+ if a:vis != ''
+ exec "normal! v"
+ endif
+
let i = 0
while i < v:count1
call search(pattern, flags)
@@ -69,53 +71,61 @@ function! s:do_search_ch(type, vis, ch)
endwhile
endfunction
-nnoremap <Plug>(supert-replace-t) <cmd>call <SID>do_search('t', '')<cr>
-nnoremap <Plug>(supert-replace-T) <cmd>call <SID>do_search('T', '')<cr>
-nnoremap <Plug>(supert-replace-f) <cmd>call <SID>do_search('f', '')<cr>
-nnoremap <Plug>(supert-replace-F) <cmd>call <SID>do_search('F', '')<cr>
-
-vnoremap <Plug>(supert-replace-t) <cmd>call <SID>do_search('t', 'v')<cr>
-vnoremap <Plug>(supert-replace-T) <cmd>call <SID>do_search('T', 'v')<cr>
-vnoremap <Plug>(supert-replace-f) <cmd>call <SID>do_search('f', 'v')<cr>
-vnoremap <Plug>(supert-replace-F) <cmd>call <SID>do_search('F', 'v')<cr>
-
-onoremap <Plug>(supert-replace-t) <cmd>call <SID>do_search('t', 'o')<cr>
-onoremap <Plug>(supert-replace-T) <cmd>call <SID>do_search('T', 'o')<cr>
-onoremap <Plug>(supert-replace-f) <cmd>call <SID>do_search('f', 'o')<cr>
-onoremap <Plug>(supert-replace-F) <cmd>call <SID>do_search('F', 'o')<cr>
+nnoremap <M-t>
+ \ <cmd>call <sid>getchar()
+ \ <bar>call <sid>do_search('t', '')<cr>
-onoremap <Plug>(supert-replace-,) <cmd>call <SID>do_search(',', 'o')<cr>
-onoremap <Plug>(supert-replace-;) <cmd>call <SID>do_search(';', 'o')<cr>
-
-vnoremap <Plug>(supert-replace-,) <cmd>call <SID>do_search(',', 'v')<cr>
-vnoremap <Plug>(supert-replace-;) <cmd>call <SID>do_search(';', 'v')<cr>
-
-nnoremap <Plug>(supert-replace-,) <cmd>call <SID>do_search(',', '')<cr>
-nnoremap <Plug>(supert-replace-;) <cmd>call <SID>do_search(';', '')<cr>
+" 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 <plug>(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("\<esc>")
+ call feedkeys(printf("%s\<plug>(srtf-post)", s:operator))
+endfunction
+" Include the bindings if the user wast to include them.
if g:supert_provide_bindings
- nnoremap <M-t> <Plug>(supert-replace-t)
- nnoremap <M-T> <Plug>(supert-replace-T)
- nnoremap <M-f> <Plug>(supert-replace-f)
- nnoremap <M-F> <Plug>(supert-replace-F)
+ onoremap Zt <Plug>(srtf-to)
+ onoremap Zf <Plug>(srtf-fo)
+ onoremap ZT <Plug>(srtf-To)
+ onoremap ZF <Plug>(srtf-Fo)
+
+ nnoremap Zt <Plug>(srtf-t)
+ nnoremap Zf <Plug>(srtf-f)
+ nnoremap ZT <Plug>(srtf-T)
+ nnoremap ZF <Plug>(srtf-F)
+
+ vnoremap Zt <Plug>(srtf-tv)
+ vnoremap Zf <Plug>(srtf-fv)
+ vnoremap ZT <Plug>(srtf-Tv)
+ vnoremap ZF <Plug>(srtf-Fv)
+endif
- vnoremap <M-t> <Plug>(supert-replace-t)
- vnoremap <M-T> <Plug>(supert-replace-T)
- vnoremap <M-f> <Plug>(supert-replace-f)
- vnoremap <M-F> <Plug>(supert-replace-F)
+" test?
- onoremap <M-t> <Plug>(supert-replace-t)
- onoremap <M-T> <Plug>(supert-replace-T)
- onoremap <M-f> <Plug>(supert-replace-f)
- onoremap <M-F> <Plug>(supert-replace-F)
+vnoremap <Plug>(srtf-tv) <cmd>call <sid>getchar()<bar>call <sid>do_search('t', '')<cr>
+vnoremap <Plug>(srtf-fv) <cmd>call <sid>getchar()<bar>call <sid>do_search('f', '')<cr>
+vnoremap <Plug>(srtf-Tv) <cmd>call <sid>getchar()<bar>call <sid>do_search('T', '')<cr>
+vnoremap <Plug>(srtf-Fv) <cmd>call <sid>getchar()<bar>call <sid>do_search('F', '')<cr>
- vnoremap <M-;> <Plug>(supert-replace-;)
- vnoremap <M-,> <Plug>(supert-replace-,)
+nnoremap <Plug>(srtf-t) <cmd>call <sid>getchar()<bar>call <sid>do_search('t', '')<cr>
+nnoremap <Plug>(srtf-f) <cmd>call <sid>getchar()<bar>call <sid>do_search('f', '')<cr>
+nnoremap <Plug>(srtf-T) <cmd>call <sid>getchar()<bar>call <sid>do_search('T', '')<cr>
+nnoremap <Plug>(srtf-F) <cmd>call <sid>getchar()<bar>call <sid>do_search('F', '')<cr>
- nnoremap <M-;> <Plug>(supert-replace-;)
- nnoremap <M-,> <Plug>(supert-replace-,)
+onoremap <Plug>(srtf-to) <cmd>call <sid>prepare_operation('t', v:operator)<cr>
+onoremap <Plug>(srtf-fo) <cmd>call <sid>prepare_operation('f', v:operator)<cr>
+onoremap <Plug>(srtf-To) <cmd>call <sid>prepare_operation('T', v:operator)<cr>
+onoremap <Plug>(srtf-Fo) <cmd>call <sid>prepare_operation('F', v:operator)<cr>
- onoremap <M-;> <Plug>(supert-replace-;)
- onoremap <M-,> <Plug>(supert-replace-,)
-endif
+" is this a question? Or is that?
+
+onoremap <Plug>(srtf-post) <cmd>call <sid>do_search_postchar('v')<cr>
+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