diff options
author | Teddy Wing | 2020-02-05 23:02:27 +0100 |
---|---|---|
committer | Teddy Wing | 2020-02-05 23:02:27 +0100 |
commit | 682926ad56ff1ce2f6498eed1cefa021dbe04839 (patch) | |
tree | 4897246eb8ceaf2f76750d4a1a3799396152e730 | |
parent | 586a637241fd00b6f3cf34d725fb923fad9007de (diff) | |
download | vim-searchop-682926ad56ff1ce2f6498eed1cefa021dbe04839.tar.bz2 |
Move functions to autoload
-rw-r--r-- | autoload/searchop.vim | 28 | ||||
-rw-r--r-- | plugin/searchop.vim | 38 |
2 files changed, 32 insertions, 34 deletions
diff --git a/autoload/searchop.vim b/autoload/searchop.vim new file mode 100644 index 0000000..6912787 --- /dev/null +++ b/autoload/searchop.vim @@ -0,0 +1,28 @@ +function! s:Search(type, ...) + let user_unnamed_register = @@ + + if a:0 + silent execute "normal! gvy" + elseif a:type == 'line' + silent execute "normal! '[V']y" + else + silent execute "normal! `[v`]y" + endif + + let @/ = substitute(escape(@@, '\'), '\n', '\\n', 'g') + call histadd('/', @/) + + let @@ = user_unnamed_register +endfunction + +function! searchop#SearchForward(type, ...) + call call('s:Search', [a:type] + a:000) + + call feedkeys('n', 't') +endfunction + +function! searchop#SearchBackward(type, ...) + call call('s:Search', [a:type] + a:000) + + call feedkeys('N', 't') +endfunction diff --git a/plugin/searchop.vim b/plugin/searchop.vim index f0a7fc6..c82e016 100644 --- a/plugin/searchop.vim +++ b/plugin/searchop.vim @@ -1,35 +1,5 @@ -nnoremap <silent> z* :set opfunc=SearchForward<CR>g@ -vnoremap <silent> z* :<C-u>call SearchForward(visualmode(), 1)<CR> +nnoremap <silent> z* :set opfunc=searchop#SearchForward<CR>g@ +vnoremap <silent> z* :<C-u>call searchop#SearchForward(visualmode(), 1)<CR> -nnoremap <silent> z# :set opfunc=SearchBackward<CR>g@ -vnoremap <silent> z# :<C-u>call SearchBackward(visualmode(), 1)<CR> - - -function! Search(type, ...) - let user_unnamed_register = @@ - - if a:0 - silent execute "normal! gvy" - elseif a:type == 'line' - silent execute "normal! '[V']y" - else - silent execute "normal! `[v`]y" - endif - - let @/ = substitute(escape(@@, '\'), '\n', '\\n', 'g') - call histadd('/', @/) - - let @@ = user_unnamed_register -endfunction - -function! SearchForward(type, ...) - call call('Search', [a:type] + a:000) - - call feedkeys('n', 't') -endfunction - -function! SearchBackward(type, ...) - call call('Search', [a:type] + a:000) - - call feedkeys('N', 't') -endfunction +nnoremap <silent> z# :set opfunc=searchop#SearchBackward<CR>g@ +vnoremap <silent> z# :<C-u>call searchop#SearchBackward(visualmode(), 1)<CR> |