As mentioned by @YoungFrog in the comments, starting with Emacs 25.1, the good-old C-h k method of describing key-binds will also tell you which keymap the key was found in.
Before Emacs 25
There’s some code
on this, but it’s incomplete as it does not cover everything. Below is an improved version of it.
Keys can be bound in 9(!) ways. ...
C-h b will list all the bindings available in a buffer. This is a mnemonic for help (C-h) bindings (b).
You can also get a list of keybindings via C-h m, which is help for the major and minor modes for the buffer. The formatting of this is a little clearer, but includes additional information about the modes beyond just listing the keybindings.
There is a "shortcut" approach too for the same solution if you don't want to define your own minor mode (that I talk about in my first answer).
You can install the use-package package available from Melpa and make use of bind-key* or bind-keys* macro that's part of the bind-key package that ships with use-package.
From the documentation of bind-key.el:
You can define your own minor mode and its key map and have that override all other modes (minor + major). That's exactly why I chose to write my own minor mode.
Steps to have your key bindings override all bindings:
Defining your own minor mode and key map as shown below.
Activate your minor mode globally
(define-key my-mode-map (kbd "C-j") #'newline-and-...
I use the command helm-descbinds, which is available via melpa. I mapped it to C-h b because it is basically a drop-in replacement for describe-bindings. The benefit is that it is easier to navigate and search than the output of describe-bindings because you can easily search for keywords and the helm buffer will narrow to show all of the matches, and ...
The future is long gone, and the stone age of computing is just about to come. All text terminals I know still send the exact same byte-sequence to Emacs for C-i as for TAB, so the original need to "unify" them is still very much with us.
The input-decode-map (à la (define-key input-decode-map "\C-i" [C-i])) is probably about as good as it gets right now.
I tested with the following script,
(when (commandp sym)
(let ((where (where-is-internal sym nil nil t)))
(setq keyseqs (append keyseqs where)))))))
(lambda (a b) (< (length b) (length a))))))
You can use with-eval-after-load to defer the key binding until after a certain module has been loaded (and thus defined the keymap):
(bind-key "M-Y" #'helm-end-of-buffer helm-map))
Use C-h v helm-map to find which module the keymap is defined in, and thus what to put in the string on the first line.
with-eval-after-load was ...
For closure, here is an answer that expands upon my comment. I define a minor mode with the required keybinding and toggle it in the required buffer using file local variables.
"Minor mode to simulate buffer local keybindings."
(define-key my-org-buffer-local-mode-map (kbd "<f10>...
Motion state is an Evil-specific thing, intended for modes where you don't edit text, but still want Vim-style movement available, with all other keys of that mode passing through. Help buffers are an example of such a case, the package.el listing is another one.
Typically you want commands moving point in evil-motion-state-map and everything else in evil-...
I don't think that this can be achieved from a terminal, but in GUI mode you could try this:
(define-key input-decode-map [?\C-i] [C-i])
(global-set-key (kbd "<C-i>") 'indent-region)
I do the same thing with C-m so that it can be distinguished from RET
The following should work whether you are in GUI or TTY mode:
;; Unbind <C-i> from ...
Taken from the Emacs Lisp Manual (see Controlling Active Maps):
To quote the manual: "It is very unusual to change the global keymap.". Safety note: Make sure you can save buffers and cleanly exit Emacs afterwards with a different keymap, otherwise you'll have to kill it without saved changes.
There is no easy way to know exactly what a single key press will do.
If you see additional behavior always check the common hooks. See the list here: http://www.gnu.org/software/emacs/manual/html_node/elisp/Standard-Hooks.html
In most cases the important ones are:
help-key-description is used to display a humanly-readable key in the documentation when you invoke describe-key (C-hk).
(help-key-description  nil) ;; --> "C-v"
(help-key-description  nil) ;; --> "C-'"
(help-key-description (kbd "C-g") nil)
;; --> t
In GUI frames (whether X11, Windows, OSX, …), Emacs reads the Tab key as the tab function key. However, because the Tab key on terminals traditionally sends the ^I (Control+I) character, Emacs translates the tab function key into the Control+I character (character 9), which is displayed as TAB. This translation is done via function-key-map.
You can do this by wrapping a call to org-agenda into a custom command and binding that to a key:
(defun org-agenda-show-unscheduled (&optional arg)
(org-agenda arg "u"))
(define-key org-mode-map (kbd "<f8>") 'org-agenda-show-unscheduled)
This turned out to be simpler then expected. As suggested in the comments here and on the question:
(make-composed-keymap (cl-copy-list erc-mode-map)
This will create a keymap which is a copy of erc-mode-...
Without remapping, you can already get by pretty well without arrow keys.
C-c C-x C-h in an Org buffer:
C-c C-x D org-shiftmetadown
C-c C-x L org-shiftmetaleft
C-c C-x R org-shiftmetaright
C-c C-x U org-shiftmetaup
C-c C-x d org-metadown
C-c C-x l org-metaleft
C-c C-x m org-meta-return
C-c C-x r org-metaright
I've got it working now, thanks to your answers:
(defun my-jump-to-tag ()
(call-interactively (key-binding (kbd "M-.")))
(define-key evil-normal-state-map (kbd "C-]") 'my-jump-to-tag)
This will set evil-state to "...
Although not the canonical emacs way of doing things, I quite like using discover-my-major for that purpose because it just feels more effective.
It is available on melpa and is powered by the makey library, which is responsible for those nice menus magit is known for.
I'd suggest you check out the github link for a screenshot demonstrating the ...
If you can't use a particular key combination because of your terminal, you can often fake it by manually simulating the key modifier. The following combinations work exactly as though you had used the corresponding modifier key:
C-x @ a alt
C-x @ m meta
C-x @ c control
C-x @ h hyper
C-x @ s super (lowercase s)
C-x @ S shift (...
Here is my super hacky way to simulate key down/up event binding by taking advantage of timers.
Overall I would suggest going by Sigma's answer, but you asked for a way to close the preview by letting go so I'm obliged to try.
Basically what you can do is bind some function that will be your "keydown" function to a keybinding and inside that action, start ...
You can use funcall and key-binding to do this:
(funcall (key-binding (kbd "C-M-j")))
will execute the function currently bound to C-M-j.
funcall lets you pass in arguments as well, if needed.
Alternatively, you can use call-interactively to call a command bound to a key like this:
(call-interactively (key-binding (kbd "C-M-j")))
In order to execute stuff after a given package is loaded, you need to put that after :config in use-package.
Here's an example using the snippet in your question:
Snippet # 1
(bind-key "M-Y" #'helm-end-of-buffer helm-map)
(bind-key "M-k" #'helm-next-line helm-find-files-map)))
Org-mode is built-in to Emacs 24.5.1, so there's no need to eval-after-load. with-eval-after-load is also preferred over eval-after-load.
Instead of trying to remap org-kill-line, why not just specify C-k?
(define-key org-mode-map (kbd "C-k") nil)
Also, there may be other modes that bind a common key like C-k. Instead, you can use C-c k. The C-(letter) ...
As pointed in comments, functions are bound to keys, not events. But to take a step back, I'm not sure I understand why it's important for you to keep the key down while you're (presumably) reading the content of the file. It would also be incompatible with basic (and reasonable) actions like scrolling to get more of it. Not to mention the fact that if it ...
The input translation maps (input-decode-map, local-function-key-map, function-key-map, key-translation-map) apply only within a key sequence. While you can specify multiple keys in the output of the translation, they'll only be counted towards binding.
For example, consider:
(define-key key-translation-map [f12] [?\C-x ?\C-f ?a])