aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2022-08-31 12:25:54 -0600
committerJosh Rahm <rahm@google.com>2022-08-31 12:25:54 -0600
commit473db604f7dbb203b3f481f0560e7abca8dfdea1 (patch)
treefba4c4e429e518c1ad0ae46885e4a92b3290c405
parent0f6857f14fc165e0c7d161a300503278315922e4 (diff)
downloadfieldmarshal.vim-473db604f7dbb203b3f481f0560e7abca8dfdea1.tar.gz
fieldmarshal.vim-473db604f7dbb203b3f481f0560e7abca8dfdea1.tar.bz2
fieldmarshal.vim-473db604f7dbb203b3f481f0560e7abca8dfdea1.zip
supert.vim: add ability to do a multiline tTfF command with meta
-rw-r--r--plugin/supert.vim115
1 files changed, 115 insertions, 0 deletions
diff --git a/plugin/supert.vim b/plugin/supert.vim
new file mode 100644
index 0000000..bd8f312
--- /dev/null
+++ b/plugin/supert.vim
@@ -0,0 +1,115 @@
+" 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 = []
+
+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, nr2char(getchar()))
+ endif
+endfunction
+
+function! s:do_last(inv, vis) abort
+ if len(s:last) < 2
+ return
+ endif
+
+ let 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 == 'v'
+ exec "norm gv"
+ elseif a:vis == 'o'
+ exec "norm v"
+ endif
+
+ let i = 0
+ while i < v:count1
+ call search(pattern, flags)
+ let i += 1
+ endwhile
+endfunction
+
+nnoremap <silent> <Plug>(supert-replace-t) :<c-u>silent call <SID>do_search('t', '')<cr>
+nnoremap <silent> <Plug>(supert-replace-T) :<c-u>silent call <SID>do_search('T', '')<cr>
+nnoremap <silent> <Plug>(supert-replace-f) :<c-u>silent call <SID>do_search('f', '')<cr>
+nnoremap <silent> <Plug>(supert-replace-F) :<c-u>silent call <SID>do_search('F', '')<cr>
+
+vnoremap <silent> <Plug>(supert-replace-t) :<c-u>silent call <SID>do_search('t', 'v')<cr>
+vnoremap <silent> <Plug>(supert-replace-T) :<c-u>silent call <SID>do_search('T', 'v')<cr>
+vnoremap <silent> <Plug>(supert-replace-f) :<c-u>silent call <SID>do_search('f', 'v')<cr>
+vnoremap <silent> <Plug>(supert-replace-F) :<c-u>silent call <SID>do_search('F', 'v')<cr>
+
+onoremap <silent> <Plug>(supert-replace-t) :<c-u>silent call <SID>do_search('t', 'o')<cr>
+onoremap <silent> <Plug>(supert-replace-T) :<c-u>silent call <SID>do_search('T', 'o')<cr>
+onoremap <silent> <Plug>(supert-replace-f) :<c-u>silent call <SID>do_search('f', 'o')<cr>
+onoremap <silent> <Plug>(supert-replace-F) :<c-u>silent call <SID>do_search('F', 'o')<cr>
+
+onoremap <silent> <Plug>(supert-replace-,) :<c-u>silent call <SID>do_search(',', 'o')<cr>
+onoremap <silent> <Plug>(supert-replace-;) :<c-u>silent call <SID>do_search(';', 'o')<cr>
+
+vnoremap <silent> <Plug>(supert-replace-,) :<c-u>silent call <SID>do_search(',', 'v')<cr>
+vnoremap <silent> <Plug>(supert-replace-;) :<c-u>silent call <SID>do_search(';', 'v')<cr>
+
+nnoremap <silent> <Plug>(supert-replace-,) :<c-u>silent call <SID>do_search(',', '')<cr>
+nnoremap <silent> <Plug>(supert-replace-;) :<c-u>silent call <SID>do_search(';', '')<cr>
+
+
+if g:supert_provide_bindings
+ nnoremap <silent> <M-t> <Plug>(supert-replace-t)
+ nnoremap <silent> <M-T> <Plug>(supert-replace-T)
+ nnoremap <silent> <M-f> <Plug>(supert-replace-f)
+ nnoremap <silent> <M-F> <Plug>(supert-replace-F)
+
+ vnoremap <silent> <M-t> <Plug>(supert-replace-t)
+ vnoremap <silent> <M-T> <Plug>(supert-replace-T)
+ vnoremap <silent> <M-f> <Plug>(supert-replace-f)
+ vnoremap <silent> <M-F> <Plug>(supert-replace-F)
+
+ vnoremap <silent> <M-t> <Plug>(supert-replace-t)
+ vnoremap <silent> <M-T> <Plug>(supert-replace-T)
+ vnoremap <silent> <M-f> <Plug>(supert-replace-f)
+ vnoremap <silent> <M-F> <Plug>(supert-replace-F)
+
+ vnoremap <silent> <M-;> <Plug>(supert-replace-;)
+ vnoremap <silent> <M-,> <Plug>(supert-replace-,)
+
+ nnoremap <silent> <M-;> <Plug>(supert-replace-;)
+ nnoremap <silent> <M-,> <Plug>(supert-replace-,)
+endif