vim-grep


Ⅰ. 插件描述

A utility for grepping that isn't limited to a specific program

Ⅱ. 基本信息

创建日期:  2013-08-07
使用用户:  4
Github星:  6
插件作者:  Chris Johnson

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'teoljungberg/vim-grep'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'teoljungberg/vim-grep'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'teoljungberg/vim-grep'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/teoljungberg/vim-grep

Ⅳ. 文档说明

# Grep

A utility for grepping that isn't limited to a specific program

Selection

  • grep.vim will try to use rg if available.
  • If rg is unavailable, and the file is in a git repo, git-grep will be used.
  • If not, it will fallback to ag.
  • If ag is unavailable, grep will be used.

Note This will clobber your g:grepprg by overwriting it whenever :Grep is
called with the appropriate tool based on the file and your environment.

Installation

Pick one of the supported alternatives: rg, ag and git-grep

Rg

You have to install rg, of
course.

Install with Homebrew:

brew install rg

Ag

You have to install ag, of
course.

Install with Homebrew:

brew install the_silver_searcher

Git grep

This comes with git, and will automatically be used when appropriate

Usage

:Grep [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
:Grep, :GrepAdd, :LGrep, and :LGrepAdd respectively.

This plugin is almost copy and pasted from [mileszs' ack.vim
plugin](https://github.com/mileszs/ack.vim).

Motion

Motions to grep for things. Works with pretty much everything, including:

w, W, e, E, b, B, t*, f*, i*, a*, and custom text objects

Normal mode

Place your cursor somewhere, type gr and, then perform a text-object for what
you want to grep for.

Visual mode

Visually select the pattern you want to grep for, type gr.

Mappings

The mapping gr is set in both normal and visual-mode, if you want to remove it
to set your own mappings you set g:grep_no_maps in your .vimrc

If you want to use qq instead of gr:

let g:grep_no_maps = 1
nnoremap <silent> qq :set opfunc=<SID>GrepMotion<CR>g@
xnoremap <silent> qq :<C-U>call <SID>GrepMotion(visualmode())<CR>

Customizing

The following options allow customization of the commands.

let g:vimgrep_rg_command="rg --vimgrep --color=never --no-heading --hidden"
let g:vimgrep_ag_command="ag --vimgrep --color=never --column --hidden"
let g:vimgrep_gitgrep_command="git --no-pager grep -n"

License

Copyright (c) Teo Ljungberg. Distributed under the same terms as Vim itself. See
:help license.

添加新评论