Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Looking at how people program their keyboard shortcuts in Emacs, I have noticed two different patterns:

One uses:

(global-set-key (kbd "M-N) 'select-next-window)

The other one:

(define-key global-map (kbd "M-N") 'select-next-window)

What's the difference between them? Don't they both define "global" keyboard shortcuts in Emacs?

share|improve this question
up vote 2 down vote accepted

Doesn't seem to be much of a difference in the major case:

  • (global-set-key key command) boils down to (define-key (current-global-map) key command)), and
  • describe-var tells us that global-map "is a keymap which is usually (but not necessarily) Emacs's global map", whereas
  • (current-global-map) "returns the current global keymap".

However, the Emacs docs talk of "the" global keymap, so it's unclear how, if ever, you can come across several global keymaps.

share|improve this answer
The variable global-map might be bound to a file or buffer local value, or it could even be bound in a let statement. – Trey Jackson Dec 15 '11 at 23:09
The global keymap is set by use-global-map. There aren't many packages that do this: mostly a few emulation modes such as Viper, and some functions such as read-char that override the global map temporarily. – Gilles Dec 16 '11 at 8:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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