Emacs and its horrible ‘Exit’ key sequence
I use Emacs nearly every day for work and even personal projects. It’s one of my favorite text editors of all time. The sheer power that it has in its built-in functionality plus the easy Elisp scripting interface within it make it a programmer’s dream. But there’s one fundamental function that I absolutely abhor. It’s the default key sequence to exit the program: C-x C-c
For those that don’t know, that basically means while holding down the Control key on the keyboard you type, in sequence, ‘x’, and then ‘c’. I hate this key combo. It has made me exit the editor accidentally and lose my workspace far too many times. The reason is that such a large amount of basic functionality in Emacs requires a key combination that starts with the C-x (Control+x) key sequence. Since the ‘c’ key is right next to the ‘x’ key on any QWERTY keyboard, there’s been far too many instances where I accidentally hit the space between them, unintentionally triggering the exit command.
Fortunately, the aforementioned programmability of Emacs comes to the rescue, here! I’ve remapped the key sequence for ‘exit’ to be C-x x (Control+x, x). It’s similar enough and easy to press but I rarely find myself accidentally inputting this sequence. And when I do accidentally press C-x C-c, instead of exiting Emacs, it will print a message in the modeline reminding me to use C-x x instead.
I used this code in my ~/.emacs file to make this change. I figure others might find it useful as well!
(global-set-key (kbd "C-x C-c") (lambda () (interactive) (message "Use C-x x to close Emacs instead."))) (global-set-key (kbd "C-x x") 'save-buffers-kill-terminal)









