Ag (the_silver_searcher) 安裝使用

來源:互聯網
上載者:User

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.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以後可以直接運行

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.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. 使用

命令列使用

ag HelloWorldag HelloWorld path/to/search

Ag HelloWorldAg HelloWorld path/to/search
在Ag尋找出來的quickfix視窗中,你可以使用下列命令:
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

詳細使用方法請查看協助:

man ag

4. Why ag

速度對比ag>ack>grep

在android全部源碼中尋找(測試環境20線程32GB記憶體):

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!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.