12

I was using Emacs on CentOS 7 from the MobaXterm terminal on Windows 7, but the backspace key instead of backward-deleting a character invokes the prefix command C-h. According to EmacsWiki, I tried to put the following lines in ~/.emacs.d/init.el:

(global-set-key (kbd "C-h") 'delete-backward-char)
(global-set-key (kbd "C-?") 'help-command)

It does make the backspace act normally, but I couldn't invoke C-h by typing either Ctrl-Shift-/ or Ctrl-h, or find anywhere to invoke it. Did I miss anything? Is it possible to let both backspace and Ctrl-h act as usual, that is, backspace doing backward-delete and Ctrl-h doing C-h help command?

2 Answers 2

13

From the Emacs manual, node DEL Does Not Delete:

On a text terminal, if you find that <BACKSPACE> prompts for a Help command, like Control-h, instead of deleting a character, it means that key is actually sending the BS character. Emacs ought to be treating <BS> as <DEL>, but it isn’t.

In all of those cases, the immediate remedy is the same: use the command M-x normal-erase-is-backspace-mode. This toggles between the two modes that Emacs supports for handling <DEL>, so if Emacs starts in the wrong mode, this should switch to the right mode. On a text terminal, if you want to ask for help when <BS> is treated as <DEL>, use <F1>; C-? may also work, if it sends character code 127.

To fix the problem in every Emacs session, put one of the following lines into your initialization file. For the first case above, where <BACKSPACE> deletes forwards instead of backwards, use this line to make <BACKSPACE> act as <DEL>:

(normal-erase-is-backspace-mode 0)

For the other two cases, use this line:

(normal-erase-is-backspace-mode 1)

Another way to fix the problem for every Emacs session is to customize the variable normal-erase-is-backspace: the value t specifies the mode where <BS> or <BACKSPACE> is <DEL>, and nil specifies the other mode.

I found this information in the Emacs manual using i backspace S-TAB, with Icicles. In Icicles, S-TAB does "apropos"-style completion, which means that it checks here for backspace as a substring, not just as a prefix, of the completion candidates.

If you try i backspace TAB then you won't find any completion candidates, because the actual candidates you need to match are these, none of which begin with backspace:

<BACKSPACE> vs <DEL>
<DEL> vs <BACKSPACE>
c-electric-backspace
C-S-backspace 
normal-erase-is-backspace
normal-erase-is-backspace-mode 
2
  • 3
    (normal-erase-is-backspace-mode 1) works for me. Thanks! Commented Sep 15, 2017 at 2:38
  • 1
    (M-x normal-erase-is-backspace-mode) works to solve the "C+h = Suppr" problem for me ! Commented Jun 15, 2022 at 9:37
2

You can also uncheck the 'Backspace sends ^H' Terminal setting in MobaXterm Configuration page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.