M-n to retrieve the current name, and edit it. E.g.,
*grep*in the minibuffer. Type
1 to change it to
Then just use
M-x grep again, to have the new search output go to the (new) buffer
As @JeanPierre pointed out in a comment, you will need to first make another buffer, besides the grep-output buffer, current (or change the mode of that buffer, so that it is not
grep-mode), before you issue the second
This is because
compilation-buffer-name to determine which buffer to use, and that function returns the name of the current buffer if the buffer is in the same mode as the command - in this case,
If you don't want to change to another buffer manually, you could change to another buffer temporarily as part of a command that wraps
grep. Or you can set or bind variable
compilation-buffer-name-function to a function that returns "grep". If that variable is non-nil then its function value is used by
compilation-buffer-name to determine the name of the buffer to use.
(defun foo (_mode)
"Return \"*grep*\" as the name of the buffer to use."
(defun my-grep ()
"`grep`, but always use buffer `*grep*'."
(let ((compilation-buffer-name-function 'foo))
Then you can use command
my-grep instead of
grep, even from a buffer that is in mode
(I just use
grep from another buffer.)