1

As I use a different language from English often I would like to create some keymaps to avoid changing languages all the time.

I don't know the name of the commands that I have to place in the section interactive-command-here of the keymap:

(define-key KEYMAP (kbd "key-bind-here") 'interactive-command-here)

For instance how can I say that I want C-σ to mean Save? How you denote the Save in the keymap?

6

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.
  • 2
    You're welcome! While you were reading the answer, I edited in a little bit more about how to find documentation in Emacs. It's cool how much one is able to ask Emacs about itself. – zck Nov 5 '14 at 5:17
  • Indeed, all you need is ask the right questions! – Adam Nov 5 '14 at 5:41
  • TIL about C-h c. I had been using only C-h k all this time for a quick key-binding lookup. – Kaushal Modi Nov 5 '14 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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