diff options
author | Teddy Wing | 2020-02-05 21:48:51 +0100 |
---|---|---|
committer | Teddy Wing | 2020-02-05 21:48:51 +0100 |
commit | 5c81308422ffdabce506e084e83fa883be535a1c (patch) | |
tree | d922161d3521a587a57177fa8697be243bdcc013 | |
parent | b49d25965be039a932264d7e954837405f60d8c9 (diff) | |
download | vim-searchop-5c81308422ffdabce506e084e83fa883be535a1c.tar.bz2 |
Add backward search mappings
Allow searching backward as well as forward.
Add new functions specific to each search direction.
Thanks to 'mattn' (https://www.reddit.com/user/mattn/) for describing
how to pass variadic arguments to a Vim function:
https://www.reddit.com/r/vim/comments/3761po/vimscript_question_passing_arguments_from_a/crk07lz/
-rw-r--r-- | plugin/searchop.vim | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/plugin/searchop.vim b/plugin/searchop.vim index ecfe2a1..a0b9835 100644 --- a/plugin/searchop.vim +++ b/plugin/searchop.vim @@ -1,5 +1,8 @@ -nnoremap <silent> z/ :set opfunc=Search<CR>g@ -vnoremap <silent> z/ :<C-u>call Search(visualmode(), 1)<CR> +nnoremap <silent> z/ :set opfunc=SearchForward<CR>g@ +vnoremap <silent> z/ :<C-u>call 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, ...) @@ -16,7 +19,17 @@ function! Search(type, ...) 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 - let @@ = user_unnamed_register +function! SearchBackward(type, ...) + call call('Search', [a:type] + a:000) + + call feedkeys('N', 't') endfunction |