https://github.com/inside/vim-grep-operator
Bring motion and visual selection to the :grep command
https://github.com/inside/vim-grep-operator
Last synced: 11 months ago
JSON representation
Bring motion and visual selection to the :grep command
- Host: GitHub
- URL: https://github.com/inside/vim-grep-operator
- Owner: inside
- Created: 2013-06-17T10:21:23.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2015-07-31T14:57:01.000Z (almost 11 years ago)
- Last Synced: 2025-03-27T16:52:05.529Z (about 1 year ago)
- Language: VimL
- Homepage:
- Size: 236 KB
- Stars: 16
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# The vim grep operator
## Description
The vim grep operator plugin, inspired by Steve Losh and
his book: http://learnvimscriptthehardway.stevelosh.com/
This plugin's has 2 goals:
* bring motion and visual selection to the :grep command
* open the quickfix window on the fly for easy file match navigation
`g{motion}` or `g` on a visual selection will produce this output:

`g{motion}` or `g` will prompt you for filenames
and will produce this output:

## Installation
Use pathogen or a pathogen compatible plugin manager.
If you are using git for source code management, you should have your grepprg
option set to something like this:
set grepprg=git\ grep\ -n\ $*
## Suggested ~/.vimrc mappings
nmap g GrepOperatorOnCurrentDirectory
vmap g GrepOperatorOnCurrentDirectory
nmap g GrepOperatorWithFilenamePrompt
vmap g GrepOperatorWithFilenamePrompt
## Choose your grep operator (default: grep)
let g:grep_operator = 'Ag'
let g:grep_operator = 'Ack'
## Configuration
Setting the search register allows hlsearch to highlight that pattern.
It also allows using the n, N motions (find next/previous pattern).
Handling the hlsearch option is up to you.
let g:grep_operator_set_search_register = 1
## Examples
`giw` will grep the current directory for the word under the cursor and
open the quickfix window.
`ga(` will grep for what's inside the parenthesis including the
parenthesis.
`gi'` will grep for what's inside the quotes.
Visually select some characters and type `g`. This will grep for the
selected text.
You can also be prompted for files to grep by using the same motions or visual
selection but with the `g` mapping.
## Useful readings
`:h grepprg`
`:h quickfix`
`:h text-objects`
http://learnvimscriptthehardway.stevelosh.com/ and specifically chapters 32, 33, 34