Here's how to set C-o
to save the current buffer:
(define-key global-map (kbd "C-o") 'save-buffer)
How did I find that function? Well, I know that the command to save the current file is C-x C-s
, so ask Emacs what the function is when you press those keys. C-h c C-x C-s
. The minibuffer tells you:
C-x C-s runs the command save-buffer
Note that I set the keybinding in the global keymap. You may or may not want to do that. If you want the keybinding only in certain modes, you should change the map specified. But if you want to always be able to press C-o
to save, that's what to do.
And, in fact, there's a slightly shorter way to set keys globally, with global-set-key
:
(global-set-key (kbd "C-o") 'save-buffer)
Note also that a very useful thing is the documentation for define-key
. Press C-h f define-key <RET>
. The beginning explains what the arguments are:
define-key is a built-in function in `C source code'.
(define-key KEYMAP KEY DEF)
In KEYMAP, define key sequence KEY as DEF.
KEYMAP is a keymap.
C-h c
. I had been using onlyC-h k
all this time for a quick key-binding lookup. – Kaushal Modi Nov 05 '14 at 13:55