1

I'm trying to do the following:

  • find all buffers containing text "foo"
  • visit each of those buffers to perform some edition

Using helm-rg, I'm forced to do this:

  • M-x helm-rg
  • Enter the text I'm looking for (foo)
  • Move in the helm-rg buffer to the first file
  • Press RET to visit the first file
  • Do my edits in this first file, save the buffer
  • M-x helm-rg
  • Enter the text I'm looking for (foo)
  • Move in the helm-rg buffer to the second file
  • Press RET to visit the second file
  • Do my edits in this second file, save the buffer
  • M-x helm-rg
  • ... etc, etc...

This gets tedious pretty quickly, and there has to be a better way. Some research mention using helm-follow-mode, or helm-resume, but in my setup it does not change anything (helm-resume does nothing after visiting a file from helm-rg.)

What would be the smart thing to do here ?

2
  • maybe able to do with a package wgrep and possibly wgrep-helm or Embark (which can export the grep (also rg, occur, etc.) result for the other action, such as wgrep) together. Commented May 12, 2023 at 14:07
  • multi-occur-in-matching-buffers perhaps? At least, all the matches stay in the Occur buffer so you don't have to repeat the search, just choose and click the next match. And next-error (C-x ` ) works to go to the next match. Commented May 12, 2023 at 21:44

1 Answer 1

0

I have the same problem. It seems helm-rg is not preserving the buffer, once you open one of its results.

This code preserves the results:

(defvar my-last-helm-rg-directory nil) (defvar my-last-helm-rg-pattern nil) (defun helm-rg-no-default () "Launch helm-rg without using the thing at point as the default search." (interactive) (let ((helm-rg-initial-input nil) (helm-rg-thing-at-point nil)) (call-interactively 'helm-rg) ;; Store the last search info (setq my-last-helm-rg-directory default-directory) (when (boundp 'helm-input) (setq my-last-helm-rg-pattern helm-input)))) (defun hukarz () "Reopen helm-rg with the last search pattern and directory" (interactive) (if (and my-last-helm-rg-directory my-last-helm-rg-pattern) (let ((default-directory my-last-helm-rg-directory)) (helm-rg my-last-helm-rg-pattern)) (message "No previous helm-rg search to resume"))) (global-set-key (kbd "C-|") 'hukarz) (global-set-key (kbd "C-\\") 'hukarz) 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.