1

I would like to be able to exit emacs without saving changes.

I might have started editing some configuration file, then decided that I don't want to save the changes.

In vi I would issue the q! command to exit the editor. I don't know if there is an emacs alternative for this.

2 Answers 2

5

To exit emacs, use C-xC-c. It will ask you whether you want to save the changes. To prevent the question, precede the combination with C-u (but it will save the changes).

If you want to kill Emacs without saving any changes, you can use the kill-emacs function (M-xkill-emacs). If you need it often, you can assing it to any key combination you like.

E.g. add this to your init file:

(global-set-key "\C-x\M-c" 'kill-emacs)
6
  • This also kill emacs daemon, how can I keep it alive?
    – alper
    Oct 20, 2021 at 9:24
  • Use C-x # to close a server editing buffer.
    – choroba
    Oct 20, 2021 at 9:42
  • I am getting following warning message and nothing happens: No server buffers remain to edit
    – alper
    Oct 20, 2021 at 9:46
  • @alper: So just close the buffer with C-x k. But that's not the point of the question. If you're running in a terminal, press C-z to put emacs into background.
    – choroba
    Oct 20, 2021 at 10:52
  • It's exact point of the question. I am using emacs to open man pages as man-mode. When I press q I just want to exit emacs without saving any changes, but keep emacs-daemon running. I don't want to suspend because it won't close the latest open buffer
    – alper
    Oct 20, 2021 at 11:57
5

In most cases, an emacs instance runs for a very long time: what comes and goes is the buffer visiting a file. So instead of killing emacs as a whole, it is probably more useful to kill the buffer that is visiting the file.

You do that with kill-buffer (usually bound to C-x k): if the buffer is modified it will ask you whether you want to kill it anyway and you can answer "yes".

1
  • 2
    This definitely the emacs style of doing the requested action. I will adopt this way of working. I accepted the kill-emacs answer because it answers the question (although the question might be ill formulated). Thanks. Sep 1, 2020 at 19:26

Your Answer

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

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