I like how Bash handles i-search: C-r, type some characters, C-r a couple more times to find the desired command, then hit Return and the command is executed.

If I want to edit the command before it's executed, I type any of C-e, C-a, C-l, <left>, <right>, which exits isearch, leaving the result on the command line.

I love using C-r to search Emacs' minibuffer history, but having to hit Return once to accept the search result and a second time to submit it is annoying. I guess it's partly psychological...

  • Me (searching): There, that's the one. Enter!
  • Emacs: um, this one?
  • Me (eyeroll): Yes, that one. Enter.

I want to fix this. Return is bound to isearch-exit in overriding-terminal-local-map. This appears to be the case both inside and outside the minibuffer. It also seems that the aforementioned map is not defined until you've entered isearch.

My current solution:

(defun ivan/isearch-exit ()
  (if (minibuffer-window-active-p (selected-window))

(defun ivan/remap-isearch-exit ()
    [remap isearch-exit]

(add-hook 'isearch-mode-hook #'ivan/remap-isearch-exit)

So far, this seems to work, but is there a cleaner approach?

  • FWIW: You might want to try this for a more powerful and more flexible way to access previously used minibuffer inputs. – Drew Jul 24 '16 at 15:42
  • Bind your command in isearch-mode-map. – politza Sep 2 '16 at 13:18
  • @politza That was the first thing I tried, but it seems overriding-terminal-local-map takes precedence over isearch-mode-map (which makes sense, given its name). – ivan Sep 2 '16 at 15:47
  • I should have guessed so. – politza Sep 2 '16 at 17:38

Your Answer

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

Browse other questions tagged or ask your own question.