reddit / emacs

Can't rebind C-h to evil-delete-char while in insert mode (Spacemacs)

snailiens · 2022-11-27 21:57
I am new to the Emacs/Spacemacs world and am having a bit of trouble adjusting. On macOS, you can do C-h in any text field to do backspace, which is nice and ergonomic to me, so I've got in the habit of using this key combination instead of the backspace key. In Emacs, I know C-h is bound to help. But in INSERT MODE, I would like to have C-h behave as backspace instead. I have tried putting the following into my user-config, but it seems to basically turn C-h into a NOP instead. Any ideas what I'm doing wrong here? (define-key evil-insert-state-map (kbd "C-h") 'evil-delete-char)
tonicinhibition · 2022-11-27 23:44
I don't use Spacemacs or MacOS, but I do have several overrides in my config. I did try your solution and it worked for me, with a couple of caveats: 1. `evil-delete-char` mimics `DEL`, not `Backspace`. 2. I use and recommend `use-package`, and tested with that I suspect that you want to use this instead: (define-key evil-insert-state-map (kbd "C-h") 'backward-delete-char) I also suspect that it isn't a NOP. Most likely you are using it at the end of a line, and there is nothing to delete afterward. Try it with the function name above. One way to check *would be* to type `C-h` `k` `C-h`. This would invoke `describe-key` and tell you what function you are actually invoking, along with documentation and keybindings. Except it won't work because you are overriding `C-h` to begin with in the specific context you need it for. You have already shot yourself in the foot! I strongly recommend not using it. Maybe use `C-y` instead, because it insert mode that defaults to `evil-copy-from-above`. No sane person would ever use that function. If you are still having trouble, you may need to put it in the :config section of your `use-package` declaration, assuming you use that. Otherwise you could wrap it in an `eval-after-load` call like this: (eval-after-load "evil" '(define-key evil-insert-state-map (kbd "C-h") 'backward-delete-char))
a-c-d-w · 2022-11-28 00:43
This is likely because Emacs sees C-h and <help> as the same thing by default. Try something like here: https://idiomdrottning.org/bad-emacs-defaults in the Ctrl-H doesn't delete backwards section
snailiens · 2022-11-28 02:26
That worked!!! Thank you so much. So far, I haven't needed to wrap it in the eval-after-load; using your define-key with 'backward-delete-char seemed to do the trick very nicely.
snailiens · 2022-11-28 02:27
Useful page, thank you! Luckily /u/tonicinhibition was able to fix my issue.