grep 대신 helm-ag(the silver searcher)

1 minute read

nil

grep으로 잘살고 있었는데, helm-ag를 봐버렸다. 오오~ 저건 live grep(Incremental grep) 아닌가.

뭘 또 새로 설치하나? grep으로 해보려는데, 빨라야 live가 되지. 너무 버벅대서 못 쓰겠다. 빨라서 많이 쓰는 ag(the silver searcher)로 바로 가려고.

ag 설치

항상 windows가 문제다. 이쪽 세계는 이렇다. 다른 OS는 고민 별로 안 해도 된다. the_silver_searcher 저장소에 있는 readme 문서를 참고해서 설치하면 된다.

windows에서는 msys2를 설치했다면 쉽게 깔 수 있다. mingw와 msys2가 잘 버무려진 git for windows sdk 설치하는 걸 추천한다. 이제 pacman 패키지 매니저로 설치하면 된다.

$ pacman -Ss silver
mingw32/mingw-w64-i686-ag 2.0.0.r1912.6cec1c3-1
  The Silver Searcher: An attempt to make something better than ack, which
  itself is better than grep (mingw-w64)
mingw64/mingw-w64-x86_64-ag 2.0.0.r1912.ccdbe93-1
  The Silver Searcher: An attempt to make something better than ack, which
  itself is better than grep (mingw-w64)

$ pacman -S mingw-w64-x86_64-ag

하지만 한글 검색에서 문제가 생겼다. grep, ripgrep로는 잘 된다. mingw64 ag 패키지가 의심된다.

helm-ag 설치

;;; https://github.com/syohex/emacs-helm-ag
(use-package helm-ag :ensure t)

live grep 함수

M-x helm-do-ag
M-x helm-do-ag-this-file
M-x helm-do-ag-project-root
M-x helm-do-ag-buffers

do 단어가 붙은 함수가 live grep이다.

키바인딩

| C-c o   | Open other window          |
| C-l     | Search in parent directory |
| C-c C-e | Switch to edit mode        |
| C-x C-s | Save ag results to buffer  |
| C-c C-f | Enable helm-follow-mode    |
| C-c >   | Move to next file          |
| C-c <   | Move to previous file      |
| C-c ?   | Show help message          |

버퍼에 ag 결과를 저장하는 기능과 편집 모드로 변경하는 기능이 유용하다.

C-x C-s C-x C-c