2018-04-21 counsel-rg and symbol at point

Continuing my streak about counsel, I had a small a-ha moment a few days ago.

I often use counsel-rg. It was rather annoying for me that I had to mark the function or variable name at point, copy it to the kill ring, invoke counsel-rg and then yank it back.

Until I realized that all this was unnecessary. It turns out (and this is even mentioned in the manual) that you can use the normal feature of Emacs, which is clairvoyance. No, seriously. When Emacs presents you with some choice to be made in the minibuffer, usually you can press M-p to go back in the history, and then M-n to go forward again. However, if you start with M-n, you move in the minibuffer history into the future, which is a probable “dwim” (do-what-I-mean) choice. If you run counsel-rg with active region, this means that M-n will fill the minibuffer with its contents. If the region is not active, it will be the symbol or url at point.

By the way, a similar thing works in swiper, too. Here we can even have two choices (at least in programming modes): just the symbol at point or the symbol at point surrounded by \_< ... \_> (which makes sense, since this means boundaries of a symbol).

Anyway, the tradition continues: if you use Emacs and at some point think “I’d like Emacs to have some feature”, chances are pretty good that it’s already supported.

CategoryEnglish, CategoryBlog, CategoryEmacs