vim-bettergrep
vim-bettergrep copied to clipboard
A better way to grep in vim.
vim-bettergrep
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
:grepwith: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
PATHin the following order:- Whatever
g:bettergrepprgis set to. - ripgrep
- ag (The Silver Seacher)
- ack
- Whatever
grepprgis set to.
- Whatever
- Asynchronous grepping.
<C-g>in normal mode mapping to:Grepin command mode.
Installation
With vim-plug:
Plug 'qalshidi/vim-bettergrep'
Usage
Either type :grep or press <C-g> and start searching your files :).

Configuration
Don't map my CTRL-G!
let g:bettergrep_no_mappings = 1
I want to use some_grepper!
let g:bettergrepprg = "<some_grepper>"
I want to use git grep!
let g:bettergrepprg = "git grep --column -n"
" or using tpope/vim-fugitive plugin's :Ggrep
I want to use git grep when my current directory is a git repository!
autocmd VimEnter * if isdirectory('./.git') | let g:bettergrepprg = 'git grep -n --column' | endif
if exists('##DirChanged')
autocmd DirChanged * if isdirectory('./.git') | let g:bettergrepprg = 'git grep -n --column' | endif
endif
Don't abbreviate my :grep!
let g:bettergrep_no_abbrev = 1
It is not ignoring my hidden files/.gitignore files!
- Use ripgrep
Frequently Asked Questions
How do I grep a pattern with spaces?
- Try enclosing your pattern in single quotes like this:
:Grep 'my pattern' my/file/path
How is this different from vim-grepper?
- vim-bettergrep is a lightweight enhancement to
:grepand 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'sautoloadfeature. They both have their own use cases. I am happy with original Vim's grep and don't necessarily need more than that.
How is this different from ack.vim?
- bettergrep is mostly like ack.vim with a bit more opinionated defaults,
quickfix window mappings that are more like
NERDTree mappings. Asynchronous
execution baked in by default. bettergrep also is more agnostic than
ack.vim albeit ack.vim is still configurable, so the command functions are
:Grepinstead of:Ack.