LoginSignup
2
0

More than 3 years have passed since last update.

counsel-rgで検索時にオプションを渡す

Last updated at Posted at 2019-11-25

tipsです。毎回忘れちゃうので。
emacsのcounselでcounsel-[rg|ag|pt]などを利用する時に、検索時にオプションを渡す方法。
下記の話は全てinteractiveで使う関数の話です

M-x counsel-rg 
[渡したいoption] -- [検索したいワード]

例: 検索対象ファイルの拡張子(html)を絞り込みたい時

sample
--glob'*.html' -- class='foobar'

注意点

  • 検索するパスを渡すことはできない
  • -i(ignore-case)や-s(--case-sensitive)オプションは自動的に付与される
  • --filesオプションを渡すことはできるが、その後--globオプションによる絞り込みはできない

(追記)打つのがめんどくさいのでこういうelispを登録すると捗ることに気が付いたので掲載

  (defun my/counsel-rg-with-extention (extention)
    "Execute counsel-rg with on cursor files EXTENTION."
    (let ((match-extention extention))
      (string-match "^[A-Za-z0-9_]+\.\\([A-Za-z0-9_\.]+\\):" match-extention)
      (counsel-rg (concat "-g'*." (match-string 1 match-extention) "' -- "))))

  (ivy-set-actions
   'counsel-rg
   '(("e" my/counsel-rg-with-extention "with-extention")))

参照

ここら辺
https://github.com/abo-abo/swiper/blob/master/counsel.el#L2811

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0