C-s 默认绑定到 isearch-forward: 不好用, swiper-isearch or swiper-isearch-thing-at-point 感觉没counsel-grep-or-swiper好用。
下面增强counsel-grep-or-swiper并绑定到C-s,超爽!可自动搜索光标下的单词或选中的
(defun dj@counsel-grep-or-swiper-at-point ()
"C-s 默认绑定到 isearch-forward: 不好用。通过增强counsel-grep-or-swiper,可以自动搜索光标下的单词、或选中的。"
(interactive)
(if (window-minibuffer-p)
(let (bnd str regionp)
(with-ivy-window
(setq bnd
(if (setq regionp (region-active-p))
(prog1 (cons (region-beginning) (region-end))
(deactivate-mark))
(bounds-of-thing-at-point 'symbol)))
(setq str (buffer-substring-no-properties (car bnd) (cdr bnd))))
(insert str)
(unless regionp
(ivy--insert-symbol-boundaries)))
(let (thing)
(if (use-region-p)
(progn
(setq thing (buffer-substring-no-properties
(region-beginning) (region-end)))
(goto-char (region-beginning))
(deactivate-mark))
(let ((bnd (bounds-of-thing-at-point 'symbol)))
(when bnd
(goto-char (car bnd)))
(setq thing (ivy-thing-at-point))))
(counsel-grep-or-swiper thing))))
(global-set-key (kbd "C-s") 'dj@counsel-grep-or-swiper-at-point)