11

A pretty basic Helm question. What is the Helm window/command/feature that lets us search for text (preferably using regexp) within any type of buffer (i.e., including read-only such as w3m)?

In other words, I'm looking for Helm's equivalent of Emacs' native commands for isearch-forward (C-s) / isearch-backward (C-r).

To illustrate: after invoking one of the native isearch commands (C-s or C-r), we can exit search mode in one of two ways:

  1. we can exit and return to original point (via C-g), or

  2. we can exit and continue browsing buffer from current point i.e., from the currently-matched text (via RET among others).

I'm looking for the second of these two options.


Here's what I've tried so far:

  • helm-regexp: this is the closest thing to what I'm looking for but it only performs the equivalent of C-s/C-r + C-g (i.e., it takes us back to the original point; no option for terminating the search and continuing to browse the buffer from the currently matched point).

  • helm-do-grep: it seems like this is only for searching for text within files (i.e., doesn't work on w3m)

  • helm-buffer-run-grep / -zgrep: running this command/function results in an error message in the mini-buffer: Running helm command outside of context

  • when helm-mode is enabled, invoking C-s or C-r brings up Emacs' native isearch feature (it isn't replaced by Helm's interface). (maybe there's a setting we can change so Helm can take over this command? i.e., similar to how Helm takes over the native command for write-file (C-x C-w) which can be used to rename a file in an open buffer. just brainstorming.)

  • 1
    You want helm-occur with follow-mode enabled. – nispio Oct 24 '14 at 22:49
16

You can use helm-occur as a tool that comes with the basic helm module for this. But to me, one of the best helm based tools for buffer searching is Shingo Fukuyama's helm-swoop. You can get it from github and via MELPA. It has your required functionality of being able to drop your point at the position of the match (which can be a regexp). But you can also use C-g to have the cursor back where you started.

On the helm-swoop github page you'll find a whole bunch of other useful functions that this package offers (including multi-buffer searches by helm-multi-swoop and the ability of editing the lines of the results, so that the changes are applied to the underlying buffer).

  • I agree. helm-swoop is really an improved version of helm-occur. – Tu Do Oct 25 '14 at 7:10
  • So, I'm obv a bit late to this front. I tried helm-swoop...and I'm never going back! Thanks – iceman Oct 26 '14 at 12:43
  • Good lord, helm-swoop is something not from this world. – Leo Ufimtsev Feb 9 '15 at 20:19
5

You can use helm-occur to see all of the lines that contain matches for your search pattern. You can use C-n and C-p to navigate the list, and then press RET to close the Helm buffer and jump your cursor to the matching line.

I like to enable helm-follow-mode when I use helm-occur so that the source window always shows the context of currently-selected match. You can enable follow-mode automatically as follows:

(require 'helm-config)

(defvar my-helm-follow-sources ()
  "List of sources for which helm-follow-mode should be enabled")

;; Use helm-follow-mode for the following sources:
(add-to-list 'my-helm-follow-sources 'helm-source-occur)

(defun my-helm-set-follow ()
  "Enable helm-follow-mode for the sources specified in the list
variable `my-helm-follow-sources'. This function is meant to
be run during `helm-initialize' and should be added to the hook
`helm-before-initialize-hook'."
  (mapc (lambda (source)
          (when (memq source my-helm-follow-sources)
            (helm-attrset 'follow 1 (symbol-value source))))
        helm-sources))

;; Add hook to enable helm-follow mode for specified helm 
(add-hook 'helm-before-initialize-hook 'my-helm-set-follow)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.