Ⅰ. 插件描述
Bring motion and visual selection to the :grep commandⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'inside/vim-grep-operator'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'inside/vim-grep-operator'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'inside/vim-grep-operator'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/inside/vim-grep-operator
Ⅳ. 文档说明
# 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
<leader>g{motion} or <leader>g on a visual selection will produce this output:

<leader><leader>g{motion} or <leader><leader>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 <leader>g <Plug>GrepOperatorOnCurrentDirectory
vmap <leader>g <Plug>GrepOperatorOnCurrentDirectory
nmap <leader><leader>g <Plug>GrepOperatorWithFilenamePrompt
vmap <leader><leader>g <Plug>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
<leader>giw will grep the current directory for the word under the cursor and
open the quickfix window. <leader>ga( will grep for what's inside the parenthesis including the
<leader>gi'will grep for what's inside the quotes.
Visually select some characters and type <leader>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 <leader><leader>g mapping.
Useful readings
:h grepprg :h quickfix :h text-objects
http://learnvimscriptthehardway.stevelosh.com/ and specifically chapters 32, 33, 34