Giter Club home page Giter Club logo

ag.vim's Introduction

ag.vim

Deprecated: See this comment for more info. Maybe try ack.vim as an alternative.

This plugin is a front for ag, A.K.A. the_silver_searcher. Ag can be used as a replacement for 153% of the uses of ack. This plugin will allow you to run ag from vim, and shows the results in a split window.

Installation

See the_silver_searcher's README for its installation instructions (if you haven't installed it already).

You have to first install ag, itself. On Mac+Homebrew, Gentoo Linux, several others, there's package named the_silver_searcher, but if your OS/distro don't have one, the GitHub repo installs fine:

Vim has various ways of installing plugins, the standard way is in the documentation, but most people use a plugin to manage their plugins. If you don't already have a preferred plugin manager plugin, why not try one of the following?

  • vim-plug

  • vim-pathogen

  • Vundle.vim

  • Or, if you don't use any sort of Vim plugin management:

    cd ~/.vim/bundle && git clone https://github.com/rking/ag.vim ag && echo "set runtimepath^=~/.vim/bundle/ag" >> ~/.vimrc

    Then open vim and run :helptags ~/.vim/bundle/ag/doc.

Configuration

You can specify a custom ag name and path in your .vimrc like so:

let g:ag_prg="<custom-ag-path-goes-here> --vimgrep"

You can configure ag.vim to always start searching from your project root instead of the cwd

let g:ag_working_path_mode="r"

Usage

:Ag [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 :Ag, :AgAdd, :LAg, and :LAgAdd respectively. (See doc/ag.txt, or install and :h Ag for more information.)

Gotchas

Some characters have special meaning, and need to be escaped your search pattern. For instance, '#'. You have to escape it like this :Ag '\\\#define foo' to search for #define foo. (From blueyed in issue #5.)

Sometimes git grep is even faster, though in my experience it's not noticeably so.

Keyboard Shortcuts

In the quickfix window, you can use:

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

Related Plugin

vim-ag-anything adds an 'ga' action to search any text object.

Acknowledgements

This Vim plugin is derived (and by derived, I mean copied, almost entirely) from milesz's ack.vim, which I also recommend installing since you might be in a situation where you have ack but not ag, and don't want to stop to install ag. Also, ack supports --type, and a few other features.

ag.vim's People

Contributors

losingkeys avatar mileszs avatar rking avatar tpope avatar blueyed avatar gcorbel avatar troydm avatar c9s avatar unceus avatar carlosgaldino avatar technicalpickles avatar lesguillemets avatar pope avatar icco avatar paulyoder avatar rstacruz avatar sayreblades avatar simono avatar wingyu avatar walnuts avatar epmatsw avatar blandinw avatar vagavond avatar nicoder avatar paulhybryant avatar wiredool avatar scintill avatar mutewinter avatar axelson avatar morenoh149 avatar

Watchers

James Cloos avatar Federico Ruggi avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.