1

I'm very new to emacs and essentially came from vim where it is not possible to bind CTRL-num combination like (CTRL-1, CTRL-2, etc) which as well as CTRL-SHIFT-xxx like CTRL-# which essentially works as simply #.

Is something like this possible in emacs?

Some Name
  • 113
  • 3

1 Answers1

2

It is perfectly possible to bind C-digit, at least in a "graphical terminal". In a text terminal, things may be different because the terminal may itself generate characters from a key combo, which then can't be seen by emacs. See this answer for discussion and links.

Actually, C-0, C-1 etc are already bound in the global map, as can be seen with the command describe-key:

M-x describe-key CTRL 1

C-1 runs the command digit-argument (found in global-map), which is an interactive compiled Lisp function in ‘simple.el’.

It is bound to C-9, C-8, C-7, C-6, C-5, C-4, C-3, C-2, C-1, C-0, ESC 0..9, C-M-9, C-M-8, C-M-7, C-M-6, C-M-5, C-M-4, C-M-3, C-M-2, C-M-1, C-M-0.

(digit-argument ARG)

Part of the numeric argument for the next command. C-u following digits or minus sign ends the argument.

You can rebind it, eg:

(global-set-key [(control ?1)] 'save-buffer)

You can do the same for #:

(global-set-key [(control ?#)] 'save-buffer)

For information on how to rebind keys, see the elisp manual chapter on keymaps.

JeanPierre
  • 7,323
  • 1
  • 18
  • 37
  • 1
    But see also https://emacs.stackexchange.com/questions/1020/problems-with-keybindings-when-using-terminal – npostavs Nov 16 '19 at 21:55
  • @npostavs Ah, yes indeed this is much more complex then, thanks for raising the issue! For now, I just added a note about that. – JeanPierre Nov 17 '19 at 10:36