Skip to content
forked from mileszs/ack.vim

Vim plugin for alternative search programs like ack or csearch.

Notifications You must be signed in to change notification settings

idbrii/vim-notgrep

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

notgrep.vim

Installation

You need to install ripgrep, ack, or codesearch.

Ack

Install on Debian / Ubuntu with:

sudo apt-get install ack-grep

For Debian / Ubuntu you can add this line into your .vimrc:

let g:ackprg="ack-grep -H --nocolor --nogroup --column"

Install on Gentoo with:

sudo emerge ack

Install with Homebrew:

brew install ack

Install with MacPorts:

sudo port install p5-app-ack

Install with Gentoo Prefix

emerge ack

Otherwise, you are on your own.

Code Search / Ripgrep

Grab the binaries and put them in your $PATH.

The Plugin

Install with pathogen.

Usage

General usage is the same across most grep-like programs:

:NotGrep [options] {pattern}

The particulars are specific to each program.

Code Search

You can use most of the same options as grep:

The -c, -h, -i, -l, and -n flags are as in grep.

As per Go's flag parsing convention, options cannot be grouped: the option pair -i -n cannot be abbreviated to -in.

Ack

Ack adds the ability to limit your search to a directory:

:NotGrep [options] {pattern} [{directory}]

Search recursively in {directory} (which defaults to the current directory) for the {pattern}.

Files containing the search term will be listed in the split window, along with the line number of the occurrence, once for each occurrence. [Enter] on a line in this window will open the file, and place the cursor on the matching line.

Just like where you use :grep, :grepadd, :lgrep, and :lgrepadd, you can use :NotGrep, :NotGrepAdd, :LNotGrep, and :LNotGrepAdd respectively. (See doc/notgrep.txt, or install and :h NotGrep for more information.)

From the ack docs:

--type=TYPE, --type=noTYPE

    Specify the types of files to include or exclude from a search. TYPE is a filetype, like perl or xml. --type=perl can also be specified as --perl, and --type=noperl can be done as --noperl.

    If a file is of both type "foo" and "bar", specifying --foo and --nobar will exclude the file, because an exclusion takes precedence over an inclusion.

    Type specifications can be repeated and are ORed together.

    See ack --help=types for a list of valid types.

Ripgrep

Behaves similarly to ack, but faster. Automatically sets up --smart-case or --ignore-case flags that match your vim settings.

Keyboard Shortcuts

In the quickfix window, you can use:

o    to open (same as enter)
go   to preview file (open but maintain focus on notgrep.vim results)
t    to open in new tab
T    to open in new tab silently
v    to open in vertical split
gv   to open in vertical split silently
q    to close the quickfix window

Suggested Mappings

nnoremap <unique> <Leader>jq :<C-u>NotGrepFromSearch<CR>
" Search for word (\b is word boundary).
nnoremap <unique> <Leader>jw :<C-u>NotGrep \b<cword>\b<CR>
nnoremap <unique> <Leader>jW :<C-u>NotGrep \b<cWORD>\b<CR>
xnoremap <unique> <Leader>jw "cy:<C-u>call notgrep#search#NotGrep('grep', '\b'. @c .'\b')<CR>
" Less precise. Similar to `*` vs `g*`.
nnoremap <unique> <Leader>jgw :<C-u>NotGrep <cword><CR>
nnoremap <unique> <Leader>jgW :<C-u>NotGrep <cWORD><CR>
xnoremap <unique> <Leader>jgw "cy:<C-u>call notgrep#search#NotGrep('grep', @c)<CR>

Integration

If AsyncCommand or another :AsyncGrep command is available, :NotGrep search will be asynchronous. Other commands (:NotGrepAdd, etc) will still be synchronous.

About

This Vim plugin is derived from ack.vim which is derived/copied from Antoine Imbert's blog post Ack and Vim Integration (in particular, the function at the bottom of the post). It generalizes the Ack command into the search tool agnostic NotGrep command. You should also check out the docs for the Perl script 'ack' : ack - grep-like text finder or the man page for csearch.

About

Vim plugin for alternative search programs like ack or csearch.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Vim Script 100.0%