A better way to grep in vim.
The purpose of this plugin is to provide a lightweight and enhanced version
of the original :grep
family of Vim commands.
This plugin implements RomainL's Instant grep + quickfix with a few of my own additions.
- Abbreviates
:grep
with:Grep
, as well as the rest::lgrep
,:grepadd
,lgrepadd
- In general faster than regular
:grep
- Autoconfigures the grep program based on what you have in your
PATH
in the following order:- Whatever
g:bettergrepprg
is set to. - ripgrep
- ag (The Silver Seacher)
- ack
- Whatever
grepprg
is set to.
- Whatever
- Asynchronous grepping if using NeoVim.
<C-g>
in normal mode mapping to:Grep
in command mode.
With vim-plug:
Plug 'qalshidi/vim-bettergrep'
Don't map my CTRL-G!
let g:bettergrep_no_mapping = 1
I want to use some_grepper
!
let g:bettergrepprg = "<some_grepper>"
I want to use git grep
!
let g:bettergrepprg = "git grep -n"
" or using tpope/vim-fugitive plugin's :Ggrep
Don't abbreviate my :grep
!
let g:bettergrep_no_abbrev = 1
I want the quickfix/location list window to open if there are results!
" Quick fix window automatically opens up if populated
augroup qfopen
autocmd!
autocmd QuickFixCmdPost cgetexpr cwindow
autocmd QuickFixCmdPost lgetexpr lwindow
augroup end
It is not ignoring my hidden files/.gitignore
files!
- Use ripgrep
How do I grep a pattern with spaces?
- Try enclosing your pattern in escaped single quotes like this:
:Grep \'my pattern\' my/file/path
Why not use Vim 8's asynchronous jobs if I'm not using NeoVim?
- I will be very happy accept a pull request :). As it stands, it is still fast without it assuming you use a faster grepper like ripgrep or The Silver Searcher.
How is this different from vim-grepper?
- vim-bettergrep is a lightweight enhancement to
:grep
and tries to imitate the original Vim commands. To me, it seems vim-grepper is beefier and its own beast, allowing multiple grep commands and loading everything at start up as opposed to using Vim'sautoload
feature. They both have their own use cases. I am happy with original Vim's grep and don't necessarily need more than that.