14 votes
Accepted

`M-[` causes emacs to print weird (possibly escape) sequences

You’re in complicated territory. A terminal emulator listens for key events from the operating system, and translates them into characters. It then sends those characters to the running application (...
user avatar
  • 11.7k
9 votes
Accepted

Keymap that is dependent on the buffer

You set shell-command as global key-binding for F1 and you add a hook function to shell-mode-hook that sets the local key binding to mode-line-other-buffer. (global-set-key (kbd "<f1>")...
user avatar
  • 30.2k
8 votes
Accepted

How can I unbind (C-M-x) globally?

eval-defun is bound to C-M-x in lisp-interaction-mode-map while global-set-key and friends operate on global-map which has lower priority than any local key-map. One way to bind C-M-x unconditionally ...
user avatar
8 votes
Accepted

How to make `C-x 9` the same as `C-x 8 "`

I can think of a couple of ways to do this. The main practical difference is whether you see C-x 8 " or C-x 9 in the minibuffer while waiting to read the next key. Option 1 is to simulate the ...
user avatar
  • 43.5k
8 votes
Accepted

How can I disable the Emacs NEWS shortcut?

(global-set-key (kbd "C-h n") nil) or (global-unset-key (kbd "C-h n")) Or interactively: M-x global-unset-key C-h n
user avatar
  • 69.6k
7 votes
Accepted

Which key prefix is left for user defined bindings?

As stated in the manual: A small number of keys are reserved for user-defined bindings, and should not be used by modes, so key bindings using those keys are safer in this regard. The reserved key ...
user avatar
6 votes
Accepted

What is the difference between C-x and C-c and the concept behind it?

The normal C-x keymap is for global bindings which are expected to do something regardless of the active modes. Conversely: Sequences consisting of ‘C-c’ followed by a control character or a digit ...
user avatar
  • 43.5k
6 votes
Accepted

What is the difference between `C-u C-c C-l` and `C-c C-l`?

Disclaimer I couldn't find a resource providing a good and understandable explanation about prefix arguments for new Emacs users. So I am a newbie and my explanation may not be the best. Prefix ...
user avatar
  • 509
6 votes
Accepted

Can't reset Ctrl-; or Ctrl-. in emacs

Once you disable C-; and C-. in GNOME Desktop, those keys will become available for Emacs to use. Use GNOME to permanently disable C-; and C-. in ibus-setup $ ibus-setup Use gsettings (preferably in ...
user avatar
5 votes
Accepted

how to map <C-M-left>, <C-M-right> etc to the correct hex codes in iterm2

You can add: For C-M-left: Send escape sequence: [1;7D For C-M-right: Send escape sequence: [1;7C For C-M-up: Send escape sequence: [1;7A For C-M-down: Send escape sequence: [1;7B And this will work ...
user avatar
  • 248
5 votes
Accepted

What exactly are keys like `<copy>`, `<paste>` etc (CUA not enabled)?

Emacs calls these function keys. Emacs usually writes their names with surrounding <...> when it interacts with you. See the Emacs manual, nodes Function Keys, Keymaps and User Input. For ...
user avatar
  • 69.6k
4 votes
Accepted

I want when "C-w" is pressed, execute delete-backward-char when no region is selected and kill-region when the region is selected

Taking you at your word, that you want to delete, and not kill, for the char and word cases, try this. (Killing is like "cut" - it not only deletes the text but puts it on the kill-ring, ...
user avatar
  • 69.6k
4 votes
Accepted

Looking for a better way to test whether the current Emacs process is running under GNU Screen

Skip all the pid stuff, and just check the STY environment variable. If it is set, then emacs is running inside screen.
user avatar
  • 11.7k
4 votes
Accepted

How to move from one source block to another, in Org-mode?

Yes, there is, run M-x org-babel-next-src-block. The default keybindings for this function are C-c C-v C-n and C-c C-v n. See also the subsection Key bindings and Useful Functions in the orgmode ...
user avatar
  • 56
4 votes

How to exit minibuffer with one key?

You want to bind keys for the minibuffer in a minibuffer keymap. If you want a key to work in all minibuffers then bind it in keymap minibuffer-local-map: (define-key minibuffer-local-map (kbd "&...
user avatar
  • 69.6k
3 votes

How to prevent `Text is read-only` when in minibuffer

You can bind the following function backward-delete-char-stop-at-read-only to the key of your choice (maybe C-h, but that binding overrides the default help key-binding). The function is essentially ...
user avatar
  • 30.2k
3 votes
Accepted

How to override org-mode-map key bindings?

Try this expression: (with-eval-after-load "org" (define-key org-mode-map (kbd "C-c C-j") #'counsel-org-goto)) The Org mode keymap "shadows" the global map. In Emacs, ...
user avatar
3 votes
Accepted

Why does `C-h b` show `??` as the command name for my key binding?

Don't bind keys to anonymous functions -- C-hb can't tell you the name of the command, because you didn't name it! Define a named function (give it a docstring too), and bind your key to that symbol. (...
user avatar
  • 43.5k
3 votes

What is the difference between `C-u C-c C-l` and `C-c C-l`?

Meta-answer: since the universal prefix argument (C-u) given once or more modifies a command's behavior, a properly-written command will thoroughly document each prefix argument. org-insert-link is ...
user avatar
  • 1,274
2 votes
Accepted

How can disable TAB to execute selected line in `counsel-M-x`?

(ivy-define-key ivy-minibuffer-map (kbd "TAB") #'ivy-partial) Originally TAB binds to ivy-partial-or-done. Note that in ivy terms, "done" means your term "execute", ...
user avatar
  • 1,017
2 votes
Accepted

How can I override an OS key binding in Emacs?

When running emacs under a graphical desktop environment, the DE uses certain keybindings for its own purposes (maximizing/minimizing/moving windows, manipulating desktops, etc.). If you try to use ...
2 votes

Which key prefix is left for user defined bindings?

Not yet mentioned, I'd like to recommend re-binding one of C-- or M--, since they both serve the same purpose. Then you have an entire key free to use.
user avatar
2 votes

Which key prefix is left for user defined bindings?

Just override any key that you don't use. Check what (if anything) is binded to a key with C-h k or install which-key-mode. You could also install something like worf or hydra make more room.
user avatar
  • 407
2 votes
Accepted

What does the `@` mean in key-shortcuts?

The @ symbol doesn't have a special meaning in a keybinding, it represents the symbol @ (i.e., Shift+2 on US keyboards). C-c @ C-f is a keybinding defined by hs-minor-mode, which elpy has apparently ...
user avatar
  • 20.3k
2 votes
Accepted

In Magit, the command `magit-status` opens the buffer with the status buffer. Is there some similar command to do the same but with the Slime's REPL?

You want slime-switch-to-output-buffer, bound to C-c C-z by default. The SLIME User Manual has the documentation for this and many other interesting commands. You can read it inside of Emacs (use C-h ...
user avatar
  • 11.7k
2 votes
Accepted

How to set key binding to `C-c C-t` in `sh-mode`?

Mode keymaps aren't defined until the defining library has been loaded, so you just need to defer binding the key until that happens. (with-eval-after-load "sh-script" (define-key sh-mode-...
user avatar
  • 43.5k
2 votes
Accepted

Can't change keybinding in prolog-mode

eval-after-load expects the first argument to be the name of a file, with or without an extension. prolog-mode is defined in the file "prolog.el", not "prolog-mode.el". This should ...
user avatar
  • 20.3k
2 votes
Accepted

Why binding M-Z to a command in org-mode with (define-key org-mode-map (kbd "<M-Z>") 'my-command) fails?

You don't want (kbd "<M-Z>"). You want (kbd "M-Z"). kbd expects the same key-description (name) syntax as that used by Emacs itself in *Help*. If you use C-h k followed by ...
user avatar
  • 69.6k
2 votes

How can I add global (usable outside of Emacs) hotkeys?

It generally requires listening to all keystrokes all the time, and swearing profusely that you’re not a keylogger. And naturally the way you implement it is quite different from OS to OS. It ...
user avatar
  • 11.7k
2 votes
Accepted

Shift+Ctrl+arrow to enlarge and shrink windows does not work in org-mode

You can override the org-mode-map like this: (define-key org-mode-map (kbd "S-C-<left>") 'shrink-window-horizontally) (define-key org-mode-map (kbd "S-C-<right>") '...
user avatar
  • 3,016

Only top scored, non community-wiki answers of a minimum length are eligible