Install and use Ag (the_silver_searcher)

Source: Internet
Author: User

If (I am a Programmer | I have a strong sense of time) I use ag

1. Install the command line ag ("\" at the beginning of the code line is redundant)

\#!/usr/bin/env bash\#Author Leslie Guan\#make sure you have the root permission\#Usage . install_ag.shset -xTEMP_DIR=$(mktemp -d Leslie.Guan.XXXXXX)cd ${TEMP_DIR}wget https://github.com/ggreer/the_silver_searcher/archive/master.zipTAR_DIR=$(unzip *.zip)TAR_DIR=${TAR_DIR%%/*}TAR_DIR=${TAR_DIR##*:}cd ${TAR_DIR}apt-get install -y automake pkg-config libpcre3-dev zlib1g-dev liblzma-dev --force-yes./build.sh && make installcd ../../rm -rf ${TEMP_DIR}ag -Vset +x

Ubuntu13.10 can be run directly

apt-get install silversearcher-ag
Ag_GitHub

2. Install the Vim plug-in ( The ag command line tool must be installed first.) (The "\" at the beginning of the line in the Code is redundant)

\#!/usr/bin/env bash\#Author Leslie Guan\#make sure you have the root permission\#Usage . install_Ag4Vim.shset -xTEMP_DIR=$(mktemp -d Leslie.Guan.XXXXXX)cd ${TEMP_DIR}wget https://github.com/rking/ag.vim/archive/master.zipTAR_DIR=$(unzip *.zip)TAR_DIR=${TAR_DIR%%/*}TAR_DIR=${TAR_DIR##*:}cd ${TAR_DIR}cp cp {plugin,autoload,doc} /usr/share/vim/vimcurrent/ -rf cd ../../rm -rf ${TEMP_DIR}
set +x

Ag. vim_GitHub

3. Use

Command Line usage

ag HelloWorldag HelloWorld path/to/search

Ag HelloWorldAg HelloWorld path/to/search
In the quickfix window found by Ag, you can use the following command:
e    to open file and close the quickfix windowo    to open (same as enter)go   to preview file (open but maintain focus on ag.vim results)t    to open in new tabT    to open in new tab silentlyh    to open in horizontal splitH    to open in horizontal split silentlyv    to open in vertical splitgv   to open in vertical split silentlyq    to close the quickfix window

For detailed usage instructions, see help:

man ag

4. Why ag

Speed comparison ag> ack> grep

Search for all the android source code (20 threads and 32 GB memory in the test environment ):

time ag -i activityreal    2m42.568suser    0m16.049ssys 1m29.358s
time ack -i activityreal    5m17.780suser    1m35.830ssys 0m17.521s
time grep -Hrni activity .real    49m27.518suser    43m13.918ssys 0m38.178s

What's so great about Ag?

It searches code about 3–5× faster than ack.It ignores file patterns from your .gitignore and .hgignore.If there are files in your source repo you don't want to search, just add their patterns to a .agignore file. *cough* extern *cough*The command name is 33% shorter than ack!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.