Skip to content

qalshidi/vim-bettergrep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 :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:
  • Asynchronous grepping if using NeoVim.
  • <C-g> in normal mode mapping to :Grep in command mode.

Installation

With vim-plug:

Plug 'qalshidi/vim-bettergrep'

Configuration

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!

Frequently Asked Questions

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's autoload feature. They both have their own use cases. I am happy with original Vim's grep and don't necessarily need more than that.