I'd like to mark regex isearch results so that they can be copied or cut (killed) via M-w and C-w. Is there a ready-made function for this?

The solution below provided by @danielpoe over here copies but does not cut. Changing kill-new to kill-region doesn't seem to work.

(defun hack-isearch-kill ()
   "Push current matching string into kill ring."
   (kill-new (buffer-substring (point) isearch-other-end))

(define-key isearch-mode-map (kbd "M-w") 'hack-isearch-kill)

If we can somehow mark the isearch results, then there would be no need for separate codes to do each job. Atom has one such package that can be used as a reference.


Your question is unclear (to me). You say you want to "mark regex isearch results" (plural). But the code you show just marks the final result - final match when you exit Isearch.

Is that what you want: just set the region around the final match, so you can use C-w or M-w on it?

If so, what was wrong with this answer on the page of your first link?

  • Isearch+ does this already. It optionally sets the region around the search target. You can use C-SPC C-SPC or M-= C-SPC at any time during Isearch to toggle this.

isearchp-deactivate-region-flag is a variable defined in isearch+.el.

Its value is t


Non-nil means isearching deactivates the region.

See also option isearchp-restrict-to-region-flag. You can toggle this option using M-= C-SPC during Isearch.

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.