0

I've redefined key bindings for some basic movement functions in my init.el file:

(global-set-key "\C-j" 'backward-char)
(global-set-key "\C-k" 'next-line)
(global-set-key "\C-l" 'forward-char)
(keyboard-translate ?\C-i ?\H-i)
(global-set-key [?\H-i] 'previous-line)

(global-set-key "\M-j" 'backward-word)
(global-set-key "\M-l" 'forward-word)

And in general (text editing) it perfectly works, but in some modes it executes multiple commands, e.g. in Buffer mode when I press C-k aside from moving the cursor down Emacs marks the listed buffer for deletion. Also, when I call helm-prelude with C-c p h and press one of these key bindings Emacs either doesn't react at all or, in case of C-k, clears the search bar. I thought that the purpose of global-set-key was to bind commands to specific keys everywhere, am I wrong?

itsjeyd
  • 5,070
  • 2
  • 30
  • 49
4lex1v
  • 21,367
  • 6
  • 52
  • 86
  • Probably a duplicate of http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs – phils Apr 01 '14 at 03:35

2 Answers2

1

Local (e.g., major-mode) keymap bindings trump global keymap (global-map) bindings. And minor-mode keymap bindings trump both of these.

There is a hierarchy of several keymap types that determines which maps take precedence. See the Elisp manual, node Controlling Active Maps (and nearby nodes about keymaps). The full hierarchy is a bit complicated, but most of the time what you need to be aware of is what I stated in the preceding paragraph.

Drew
  • 29,895
  • 7
  • 74
  • 104
0

Yes, the global keymap is only used when there is no binding for the key being pressed in a local keymap. For example, the buffer menu mode uses Buffer-menu-mode-map, where C-k is bound to Buffer-menu-delete.

You may have better luck using keyboard-translate to translate these keys to the "normal" Emacs bindings for those commands, i.e. C-p, C-n etc.

legoscia
  • 39,593
  • 22
  • 116
  • 167