Questions tagged [keymap]

A keymap is a Lisp data structure that specifies key bindings for various key sequences. A single keymap directly specifies definitions for individual events. When a key sequence consists of a single event, its binding in a keymap is the keymap's definition for that event.

A keymap is a Lisp data structure that specifies key bindings for various key sequences. A single keymap directly specifies definitions for individual events. When a key sequence consists of a single event, its binding in a keymap is the keymap's definition for that event.


The binding of a longer key sequence is found by an iterative process: first find the definition of the first event (which must itself be a keymap); then find the second event's definition in that keymap, and so on until all the events in the key sequence have been processed.

If the binding of a key sequence is a keymap, we call the key sequence a prefix key. Otherwise, we call it a complete key (because no more events can be added to it). If the binding is nil, we call the key undefined. Examples of prefix keys are C-c, C-x, and C-x 4. Examples of defined complete keys are X, enter, and C-x 4 C-f. Examples of undefined complete keys are C-x C-g, and C-c 3. See Prefix Keys, for more details.

The rule for finding the binding of a key sequence assumes that the intermediate bindings (found for the events before the last) are all keymaps; if this is not so, the sequence of events does not form a unit—it is not really one key sequence. In other words, removing one or more events from the end of any valid key sequence must always yield a prefix key. For example, C-f C-n is not a key sequence; C-f is not a prefix key, so a longer sequence starting with C-f cannot be a key sequence.

The set of possible multi-event key sequences depends on the bindings for prefix keys; therefore, it can be different for different keymaps, and can change when bindings are changed. However, a one-event sequence is always a key sequence, because it does not depend on any prefix keys for its well-formedness.

At any time, several primary keymaps are active—that is, in use for finding key bindings. These are the global map, which is shared by all buffers; the local keymap, which is usually associated with a specific major mode; and zero or more minor mode keymaps, which belong to currently enabled minor modes. (Not all minor modes have keymaps.) The local keymap bindings shadow (i.e., take precedence over) the corresponding global bindings. The minor mode keymaps shadow both local and global keymaps. See Active Keymaps, for details.

248 questions
72
votes
4 answers

How can I find out in which keymap a key is bound?

I have rebound a the 'd' key in gnus-article-mode, but its old behavior is still active when the point is on an attachment. I can see that the rebinding did not take effect there by doing C-h k d, but it is not telling me what keymap is in effect at…
brab
  • 925
  • 1
  • 7
  • 8
65
votes
8 answers

How do I list all key-bindings available in a given buffer?

I am trying out a new major mode, how can I take advantage of Emacs' documentation system to get a listing of key bindings available in that specific buffer?
nixeagle
  • 2,407
  • 3
  • 17
  • 14
54
votes
6 answers

How to override major mode bindings

Sometimes my global keybindings are overridden by a major mode. An easy example is the following setting in my init file (global-set-key (kbd "C-j") 'newline-and-indent) But annoyingly this keybinding is hidden by the "Lisp Interaction" major mode…
nispio
  • 8,175
  • 2
  • 35
  • 73
30
votes
1 answer

How to distinguish C-i from TAB?

Normally, for historic reasons, emacs treats the TAB keycode and the C-i key as the same, cf. the emacs lisp documentation on function keys or abo-abo's answer on the question "What is the difference between TAB and ?". NOTE: In this post, keycodes…
elemakil
  • 2,517
  • 1
  • 18
  • 26
19
votes
1 answer

Differences between evil-normal-state-map and evil-motion-state-map

Documentation for evil-normal-state-map: Keymap for Normal state. Documentation for evil-motion-state-map: Keymap for Motion state. Does Vim have a so-called "motion mode"? In Vim, executing :help Normal-mode would give you the documentation on…
nalzok
  • 665
  • 6
  • 18
19
votes
7 answers

Dired "quick-view" key to preview the file at point

I would like to create a function that does a "quick view" of a file the is under point in dired. The way that I would like for this to work is that I hold down a function key, which then makes the file visible in a buffer, but when I let off of…
Eric Brown
  • 3,212
  • 4
  • 16
  • 20
19
votes
2 answers

How to bind C-i as different from TAB?

I want to make Control-i perform indent-region (basically since Xcode has built that muscle memory already). I realise that Control-i and tab are indistinguishable in the Ascii sense, but they are in the keycode sense. I've tried the…
Mark
  • 1,409
  • 1
  • 15
  • 20
17
votes
2 answers

How to bind a key to a specific agenda command/list in org mode

I've added a custom key for the org agenda to show all unscheduled TODO items following Sacha Chua: (defun sacha/org-agenda-skip-scheduled () (org-agenda-skip-entry-if 'scheduled 'deadline 'regexp "\n]+>")) (setq org-agenda-custom-commands …
rneatherway
  • 483
  • 3
  • 11
17
votes
2 answers

Key bindings specific to a buffer

Is it possible to set key bindings specific to buffer? I have the following in one of my org files: # Local Variables: # eval: (local-set-key (kbd "") 'some-custom-defun-specific-to-this-buffer) # End: But this binding persists for other…
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
16
votes
2 answers

How to find out what a key sequence really does

From time to time I observe unexpected behavior when editing text. My first recourse is usually to use C-h k to find out what functions are being called by a given key sequence. However, sometimes the documentation is at odds with the observed…
nispio
  • 8,175
  • 2
  • 35
  • 73
14
votes
7 answers

Evil: map keybindings the vim way?

I am trying to make the Evil function evil-jump-to-tag, C-] behave like the Emacs binding M-.. The normal behaviour is fine for browsing Tags files, but I want it to work also for Slime's slime-edit-definition, Elisps'…
martin
  • 356
  • 3
  • 10
14
votes
3 answers

What is the longest known key sequence in Emacs?

Qt supports Emacs-style keybindings, however for only up to four keys. To make a point why this limit should be increased it would be useful to show examples of Emacs-style keybindings with even more keys than that. Are there any known examples…
wasamasa
  • 21,803
  • 1
  • 65
  • 97
13
votes
2 answers

org-mode sans arrow keys

Org-mode keymapping defaults to using the arrow keys for commons functions. Has anyone sanely remapped their org-mode settings to entirely avoid arrow keys? Please share.
Jeff Bauer
  • 861
  • 1
  • 10
  • 22
12
votes
2 answers

How to switch keyboard layouts for different languages?

Q: how do I switch between input methods for different languages when using a non-standard keyboard layout? I have to edit text in two different languages. I would like to be able to use my keybindings across the two languages, except, of course,…
Dan
  • 32,584
  • 6
  • 98
  • 168
12
votes
1 answer

How to remap Company's select next and select previous keys?

I don't like the default M-n and M-p keys for company-select-next and company-select-previous so I was wondering if it's possible to remap those to C-n and C-p without affecting the mappings when company's tooltip is not active.
caisah
  • 4,056
  • 1
  • 23
  • 43
1
2 3
16 17