reddit / emacs

Trying emacs again. remap `C-x` everywhere?

LastCenturyMan · 2022-08-14 20:34
​ I tried emacs out in the late 90s, and gave up because I couldn't remap \`C-x\` to \`'next-line\` (I still use WordStar keybindings, mock away). I thought I'd try again. It's been 25 years. Surely you can re-map \`C-x\` by now? It even has evil-mode, so it might work. It doesn't work. At least I can't get it to work. It works fine if I open a file and do normal stuff. As soon as I try to use \`counsel-describe-function\` or really almost anything in the mini-buffer at all... blamo. \`C-x\` is mapped to something else, and I get \`Key Sequence C-x X starts with non-prefix key C-x\` So, is there a way to fix this? Or should I just try again in 25 years? \--- Update for Posterity --- This effectively can't be done. If you want to map C-x or C-c to a non-prefix command, every time you open a file and some minor-mode kicks in, it can remap if it wants to. And lots of modes add keys to the C-x or C-c prefix, thereby un-mapping your command. I guess it might be possible w/ a metric-ton of emacs-foo, but I don't think it's possible for the mere mortal. I've tried 3-4 different approaches I've found around the web. They all break in another way within an hour of actual use. In general, I don't think you can really manage custom keybinding that work near-globally at all. I think you either have to use emcs's defaults w/ small tweaks, or evilMode which does all this work (mostly, it still fails to map vi-bindings when some minor-modes kick in). So, 25 years later? Same concussion as before. Ironicaly emacs is one of the most un-customizable editors when it comes to keybindings. To be fair, vim has similar problems. But most of those come from the terminal not passing/knowing certain keys. Can't remap C-; in vim easily either. It's too bad. I was enjoying emacs for the hour or so before it break.
Alan_Shutko · 2022-08-14 21:02
Have you considered trying wordstar-mode? M-x load-library RET ws-mode RET M-x wordstar-mode
LastCenturyMan · 2022-08-14 21:42
>considered trying words it says "Package ws-mode is deprecated" But it seems to work better than what I did. Maybe I'll checkout the source and see if there is some magic in there.
00-11 · 2022-08-14 23:54
A lot of us are beyond our expiration date but still somewhat useful...
MitchellMarquez42 · 2022-08-15 01:40
[General.el](http://github.com/noctuid/general.el) does some things in the background with keybindings, might help.
LastCenturyMan · 2022-08-15 01:44
I \*think\* I got this to work, by defining a minor-mode. Then "just" adding a ton of \`add-hook\` calls to turn it on everyplace I want it. Which is almost every place. Kinda annoying, but it works so far.
Hammar_Morty · 2022-08-15 01:47
Just on my phone as I should be going to bed but how did you attempt to rebind 'C-x'? I would rebind the [ctrl-x-map](https://www.gnu.org/software/emacs/manual/html_node/elisp/Standard-Keymaps.html) but haven't actually tried yet.
s-kostyaev · 2022-08-15 06:44
Why not global minor mode and enable it once?
Horrih · 2022-08-15 07:25
For remapping on another binding (e.g C-a) i believe it should be as simple as (define-key (kbd "C-a") ctl-x-map) (define-key (kbd "C-x) 'next-line)
LastCenturyMan · 2022-08-16 00:13
I tried that, but since the order it applies the minor modes are uncontrollable, it's a bit of a mess. I couldn't get it to work.
LastCenturyMan · 2022-08-16 00:16
That's what I tried at first. But it turns out different modes (ivy, or something) remap it. So after returning from a search, it's no longer bound. That was my experience 25 years ago. It is/was hard-coded in a bunch of places. So either stuff blew up, or it got magically re-mapped.
LastCenturyMan · 2022-08-16 01:23
After paying around more, I did end up trying general.el. Much cleaner. Thanks!
[deleted] · 2022-08-16 04:17
[deleted]