ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Ag (the_silver_searcher) 安装使用

2019-07-23 10:03:12  阅读:300  来源: 互联网

标签:searcher TAR ag TEMP Ag cd open silver DIR


原文链接:http://www.cnblogs.com/GMCisMarkdownCraftsman/p/3795315.html

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


1. 安装命令行ag(代码中行首的“\”是多余的)

\#!/usr/bin/env bash
\#Author Leslie Guan
\#make sure you have the root permission
\#Usage . install_ag.sh
set -x
TEMP_DIR=$(mktemp -d Leslie.Guan.XXXXXX)
cd ${TEMP_DIR}
wget https://github.com/ggreer/the_silver_searcher/archive/master.zip
TAR_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 install
cd ../../
rm -rf ${TEMP_DIR}
ag -V
set +x 

ubuntu13.10以后可以直接运行

apt-get install silversearcher-ag

ag_GitHub

2. 安装Vim插件(必须先安装ag命令行工具)(代码中行首的“\”是多余的)

\#!/usr/bin/env bash
\#Author Leslie Guan
\#make sure you have the root permission
\#Usage . install_Ag4Vim.sh
set -x
TEMP_DIR=$(mktemp -d Leslie.Guan.XXXXXX)
cd ${TEMP_DIR}
wget https://github.com/rking/ag.vim/archive/master.zip
TAR_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. 使用

命令行使用

ag HelloWorld
ag HelloWorld path/to/search
Ag HelloWorld
Ag HelloWorld path/to/search

在Ag查找出来的quickfix窗口中,你可以使用下列命令:

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

详细使用方法请查看帮助:

man ag

4. Why ag

速度对比ag>ack>grep

在android全部源码中查找(测试环境20线程32GB内存):

time ag -i activity
real    2m42.568s
user    0m16.049s
sys 1m29.358s
time ack -i activity
real    5m17.780s
user    1m35.830s
sys 0m17.521s
time grep -Hrni activity .
real    49m27.518s
user    43m13.918s
sys 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!

转载于:https://www.cnblogs.com/GMCisMarkdownCraftsman/p/3795315.html

标签:searcher,TAR,ag,TEMP,Ag,cd,open,silver,DIR
来源: https://blog.csdn.net/weixin_30808693/article/details/96968785

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有