4

How can I move my cursor left and right while entering my isearch text?

  1. isearch-forward
  2. Enter some text
  3. Press cursor left to edit the search text

Argh! Emacs returns the cursor to the main buffer.

I tried (setq isearch-allow-scroll t), but this doesn't seem to do anything. I even tried (setq search-exit-option nil), which gives an error, even with emacs -q.

Error in pre-command-hook (isearch-pre-command-hook): (wrong-type-argument characterp left)
5

You can run the command isearch-edit-string pressing M-e. See the documentation for details.

  • Thankyouthankyouthankyou. This has driven me nuts forever. I looked everywhere for this! – forthrin Apr 8 '18 at 6:53
3

@matteol answered your question. Here is some further info about this.

During Isearch, keys you press that are defined in isearch-mode-map act according to their bindings there. Keys that are not defined in that keymap act as they would outside Isearch.

By default, C-b is not bound in isearch-mode-map, and its global-map binding of backward-char is invoked when you use it during Isearch. That exits Isearch. Likewise for <left> (bound to left-char globally) and other cursor-movement keys.

If you use Isearch+ then you can customize user option isearchp-initiate-edit-commands to specify that various commands (typically cursor movement commands) should not exit Isearch but should instead initiate Isearch edit.

This is a convenience feature, so you can just hit <left> or C-b to both: (1) initiate editing of the Isearch pattern and (2) move the cursor within that pattern. This is so convenient that by default the option value does include both <left> and C-b (as well as M-<left>, M-b, C-M-<left>, and C-M-b, which back the cursor up by a word and a sexp, respectively).

C-h v isearchp-initiate-edit-commands says:

isearchp-initiate-edit-commands is a variable defined in isearch+.el.

Its value is (backward-char left-char backward-sexp backward-word left-word)

This variable can be risky when used as a file-local variable.

Documentation:

Commands whose key bindings initiate Isearch edit.

When invoked by a key sequence, Isearch edits the search string, applying the command to it immediately.

Commands you might want to include here are typically commands that move point to the left, possibly deleting text along the way.

Set this to nil if you always want all such commands to exit Isearch and act on the buffer text.

You can customize this variable.

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.