There are buffers that prevent you from being able to execute interactive commands (by overriding the default M-x binding). For example, *ansi-term* buffer would do this.

(I know you can do C-cM-x to invoke the command).

Is there an existing way to rename a buffer that isn't the current buffer? (It's easy to write a function for it, but it seems like it should've been already written...)

  • As far as I know, there is no predefined command to rename a buffer other than the current one (e.g. read a buffer name). It's easy to define such a command, though.
    – Drew
    Oct 22, 2020 at 17:47
  • @Drew Well, I guess, I'll have to accept that I have to write such a function.
    – wvxvw
    Oct 25, 2020 at 14:45
  • You might want to wait a bit, to see if someone else provides info about this. I may be mistaken.
    – Drew
    Oct 25, 2020 at 17:44

1 Answer 1


In case anyone is looking for a function that can rename a buffer that isn't the current buffer, here's one way to do it.

(defun rename-another-buffer (buffer new-name)
  "Rename a buffer that isn't the current buffer."
  (with-current-buffer buffer
    (rename-buffer new-name)))

It uses with-current-buffer to temporarily make the given buffer the current buffer so that rename-buffer can be used on it.

  • I would venture that the OP was looking for an interactive command, where you select a buffer to be renamed first interactively.
    – Arktik
    Mar 17, 2023 at 17:34

Your Answer

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

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