可以用 git grep
git grep xxx
真是太好用了 :)
不是 git 倉庫怎麼辦?
ag
A code searching tool similar to ack
, with a focus on speed.
和ack類似,但是 ag 更快,軟件開發 唯快不破 :)
ubuntu 源碼安裝
git clone https://github.com/ggreer/the_silver_searcher.git
sudo apt-get install -y automake pkg-config libpcre3-dev zlib1g-dev liblzma-dev
cd the_silver_searcher
./build.sh
sudo make install
ubuntu 安裝
apt-get install silversearcher-ag
centos 安裝
yum install the_silver_searcher
查看版本號
~/kubernetes/docker $ ag --version
ag version 2.1.0
Features:
+jit +lzma +zlib
使用
ag wjs\.
hello.go~
9: log.Print("hello world", wjs.Add(5,6))
hello.go
9: log.Print("hello world", wjs.Add(5,6))
搜索 所有的 go 文件 類似於 (find -name *.go)
ag -g *.go
emacs 下用 ag
git clone https://github.com/Wilfred/ag.el.git
(add-to-list 'load-path "/home/wjs/emacs/ag.el")
(require 'ag)
在公司電腦裝的時候發現 缺乏了 dash.el 和 s.el
git clone https://github.com/magnars/s.el.git
git clone https://github.com/magnars/dash.el.git
(add-to-list 'load-path "~/emacs/dash.el")
(add-to-list 'load-path "~/emacs/s.el")
(add-to-list 'load-path "~/emacs/ag.el")
(require 'ag)
(global-set-key "\C-\M-f" 'ag-files)
emacs 下用起來 簡直神器了啊 :)
M-x ag RET
指定搜索字符串 RET 比如我輸入了 main(
指定搜索目錄 RET
C-h m 一下 找找看 這個Model裏有哪些快捷鍵
p 跳轉到上一個結果
n 跳轉到 下一個結果
再按 Enter
就會在另一個 buffer 裏打開這個文件 並定位到 該字符串處
還可以用 ag-files
可以指定僅搜索文件後綴
M-x ag-files
Search string (default main): main(
Select file type: c
Filenames which match PCRE: \.c
Directory: ~/cpp/
更多用法 請參考