From 9de2e215ca473de3441746788b1cc85bde9c87f3 Mon Sep 17 00:00:00 2001 From: Wynn Wolf Arbor Date: Fri, 5 Jun 2020 21:37:18 +0200 Subject: Initial import. --- .gitignore | 1 + README.md | 6 +++++ doc/ripgrep.txt | 34 +++++++++++++++++++++++++++ plugin/vim-ripgrep.vim | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 doc/ripgrep.txt create mode 100644 plugin/vim-ripgrep.vim diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a56e3f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/doc/tags diff --git a/README.md b/README.md new file mode 100644 index 0000000..13fc17a --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# vim-ripgrep - Invoke rg(1) from within vim + +vim-ripgrep is a small plugin that integrates [ripgrep](https://github.com/BurntSushi/ripgrep) +into vim seamlessly. + +See [doc/ripgrep.txt](../tree/doc/ripgrep.txt). diff --git a/doc/ripgrep.txt b/doc/ripgrep.txt new file mode 100644 index 0000000..c050953 --- /dev/null +++ b/doc/ripgrep.txt @@ -0,0 +1,34 @@ +*ripgrep.txt* Invoke rg(1) from within vim. + +============================================================================== + SYNOPSIS *ripgrep* + +vim-ripgrep is a small plugin that integrates ripgrep into vim seamlessly. It +provides a single command, |:Rg|, to do this. + +This plugin is only available if |'compatible'| is not set. + +============================================================================== + COMMANDS *ripgrep-commands* + + *ripgrep-:Rg* +:Rg [args] Run ripgrep in vim's current directory with the + given arguments. When nothing is passed, search for + the |word| under the cursor. + + If |'ignorecase'| or |'smartcase'| is set, |:Rg| will + pass the corresponding option to ripgrep. + + |:Rg| will automatically open the quickfix list if + there are any matches. + +============================================================================== + ABOUT *ripgrep-about* + +vim-ripgrep was written by Wynn Wolf Arbor. It was heavily inspired by another +plugin called vim-ripgrep (https://github.com/jremmen/vim-ripgrep), but was +written from scratch with simplicity in mind. + +Obtain the latest version at https://git.oriole.systems/vim-ripgrep + + vim:tw=78:et:ft=help:norl: diff --git a/plugin/vim-ripgrep.vim b/plugin/vim-ripgrep.vim new file mode 100644 index 0000000..fc1bd58 --- /dev/null +++ b/plugin/vim-ripgrep.vim @@ -0,0 +1,63 @@ +if exists('g:rg_plugin_loaded') || &compatible + finish +endif + +let g:rg_plugin_loaded = 1 + +let g:rg_binary = 'rg' +let g:rg_args = ' --vimgrep' +let g:rg_format = '%f:%l:%c:%m' + +fun! s:err(msg) + echohl ErrorMsg | echo a:msg | echohl None +endfun + +fun! s:ArgsOrCword(args) + if empty(a:args) + return expand('') + else + return a:args + endif +endfun + +fun! s:PerformSearch(args) + if empty(a:args) + call s:err('No search pattern given and was empty.') + return + endif + + let l:opts = ' ' + if &ignorecase + let l:opts = l:opts . '-i ' + endif + if &smartcase + let l:opts = l:opts . '-S ' + endif + + silent exe 'grep! ' . l:opts . a:args + + if len(getqflist()) + exe 'copen' | redraw! + else + cclose | redraw! + echo 'No match found for ' . a:args + endif +endfun + +fun! s:WithRgContext(fun, args) + let l:prev_grepprg = &grepprg + let l:prev_grepformat = &grepformat + let &grepprg = g:rg_binary . g:rg_args + let &grepformat = g:rg_format + + call a:fun(a:args) + + let &grepprg = l:prev_grepprg + let &grepformat = l:prev_grepformat +endfun + +fun! s:Rg(args) + call s:WithRgContext(function('s:PerformSearch'), s:ArgsOrCword(a:args)) +endfun + +command! -nargs=* -complete=file Rg call s:Rg() -- cgit v1.2.3-2-gb3c3