4

I often use isearch (C-s normally or / in evil) and then want to use that query (or part of it) for replacing. This answer explains how to cycle history, but M-p cycles the history for each mode separately so I don't see isearch queries from query-replace.

Ideally, the query I used for either search is automatically saved and I can use a key binding to insert the query into a buffer or minibuffer.

Example: search for "fib-function", C-h f and insert "fib-function" for help, or helm-do-grep to search for it in files, or just insert it into the current file to start defining it.

4
  • If you use Helm, you could use helm-minibuffer-history that shows all inputs. and bind it to a key in isearch-mode-map.
    – Tu Do
    May 11, 2015 at 12:39
  • Using this: (define-key isearch-mode-map (kbd "C-u") 'helm-minibuffer-history) causes my entire buffer to be replaced with whatever I select from the history (and I can only select the first item). Also, I can't use that to insert into helm: helm: Error: Trying to run helm within a running helm session.
    – idbrii
    May 11, 2015 at 13:07
  • Weird, working fine for me in Isearch. So, try (define-key isearch-mode-map (kbd "C-c C-l") 'helm-minibuffer-history) if it works. Are you using Spacemacs? Also, if you see a Helm buffer that gives you a list of strings, it's working as expected. Select an item from the list and press RET. Then the input will be inserted into the minibuffer.
    – Tu Do
    May 11, 2015 at 13:13
  • I am using spacemacs and using / to start isearch. I get the same result with that map: I get a helm buffer giving a list of strings separated by ----, but I can't type to narrow down the list and I can't use C-j to move down the list. Typing anything narrows the list to helm-minibuffer-history (the first item in the list). Then my buffer is replaced with helm-minibuffer-history.
    – idbrii
    May 12, 2015 at 15:19

1 Answer 1

6

Customize option query-replace-from-history-variable (or query-replace-to-history-variable, or both). Point to search-ring or regexp-search-ring instead of query-replace-history.

1
  • Thanks! (setq query-replace-from-history-variable 'regexp-search-ring) worked to join the spacemacs / history with visual-regexp-steroids. For anyone following along at home, the from refers to the search history and to means the replacement history, so you can track them independently. C-h v explains what they mean.
    – idbrii
    May 12, 2015 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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