silver searcher
grep代替のツール。便利そうなので入れてみた。
$ ag hoge
を実行するだけで、カレントディレクトリ以下を検索してくれる。かつ.gitignoreなどを無視してくれる。
メリットは以下
- 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, and all keys are on the home row!
なんで速いのかは以下。
- Searching for literals (no regex) uses Boyer-Moore-Horspool strstr.
- Files are mmap()ed instead of read into a buffer.
- If you're building with PCRE 8.21 or greater, regex searches use the JIT compiler.
- Ag calls pcre_study() before executing the regex on a jillion files.
- Instead of calling fnmatch() on every pattern in your ignore files, non-regex patterns are loaded into an array and binary searched.
- Ag uses Pthreads to take advantage of multiple CPU cores and search files in parallel.
ついでにag.vimを入れてみる
NeoBundleを利用しているので、.vimrcに以下を記述
NeoBundle 'rking/ag.vim'
:NeoBundleInstall
を実行
あとは
:Ag hoge
で検索可能