More isearch Goodness

In A Nice Emacs Trick, I wrote about how you can enter query-replace or query-replace-regexp directly from isearch and use the isearch search string as the FROM parameter to query-replace or query-replace-regexp. It turns out that there's a lot more isearch goodness available.

Steve Purcell, who I first talked about in Zap Up To A Character, has a nice collection of isearch enhancements. One of these merely drew my attention to functionality that's already there but hardly anyone knows about: you can call occur directly from isearch using the search string for the input to occur by calling isearch-occur. That's bound to 【Meta+s o】 by default but Purcell binds it to the easier 【Ctrl+o】:

(define-key isearch-mode-map (kbd "C-o") 'isearch-occur)

Another common use case is wanting to end the isearch on the other side of the match. For example, if you are searching forward but want to put point before the match instead of after it you have to do something special to get it there. With a single word for the match,【Meta+b】 does the trick but more complicated matches (multiple words, say) aren't as easy. Purcell provides isearch-exit-other-end to do this and binds it to the very sensible【Ctrl+Return】:

(define-key isearch-mode-map [(control return)] 'isearch-exit-other-end)

I've already added both of these to my init.el.

There are a couple of other enhancements in Purcell's init-isearch.el file so be sure to head over and take a look. Perhaps you'll want to add some of the others.

This entry was posted in General and tagged . Bookmark the permalink.
  • Phil

    I think the most important thing to keep in mind is that after initiating isearch, you type C-h twice to get its help menu, which then gives you easy access to the isearch-forward help screen, and the full list of isearch keybindings, which you definitely want to look through.

  • dmitry

    Thanks! Occur makes log analysis a lot easier.