reddit / emacs

Evil keybinding for emacs from scratch

aminevsaziz · 2022-11-05 13:31
As noobie to emacs (6 months) I used spacemacs then doom emacs. However I didn't like both they were bloated with a lot of features that I don't know they exist. When things break you need to ask for help. I started watch how to build you custom config from scratch and I tried and I like it so much. Adding packages one by one after I know they are useful for me. I learned a lot more than the 6 months with doom and spacemacs. Now, I want to setup evil keybinding like doom and space emacs but it's overwhelming and confusing. I tried looking into space/doom configs that involve packages I use in but I found a lot of custom functions there's no logic to the keybinding. My question, is there any reference that I can use as help or template in my journey to setup evil keybinding. P.s: I don't mind templates for emacs binding as long the logic is explained so I can follow the same or adapt.
alcanost · 2022-11-05 14:30
Just [like this?](https://github.com/emacs-evil/evil#installation)
cmagnificent · 2022-11-05 14:44
Are you trying to install Evil using vanilla Emacs (not Doom/Spacemacs), or are you looking for a way to set up a custom modal/modal-like experience within emacs, using evil/vim style keybindings? If it's the first, and you want Evil itself: `M-x package-refresh-contents RET` `M-x package-install RET evil RET` Then, in your init, place the following: `(require 'evil)` `(evil-mode 1)` And happy eviling! If it's the latter and you're looking for a way to set up vim/evil like keybindings yourself (separate links for each), [Modalka,](https://github.com/mrkkrp/modalka) [RYO-modal,](https://github.com/Kungsgeten/ryo-modal) and [Meow](https://github.com/meow-edit/meow) (and probably a few dozen others 'cause emacs) allow you to do that. Of those, I use Modalka because, most importantly, it was the first I tried and it's worked fine so far, and additionally because Modalka is very minimalist and non-intrusive; my config for Modalka has more lines of code than the package for Modalka. If worse came to worse I could probably maintain the code base, at least for personal use.
aminevsaziz · 2022-11-05 15:34
I'm looking for keybinding. I do know how to install evil and evil-collection but the issue with evil is the keybinding. For example evil-collection provide bare bindings (for example consult) and there's no alternative or a template new commers like me would like to use for setting the config. I tried modlka, meow, boon and God but all feels the same, just a less "Ctrl" mode.
MitchellMarquez42 · 2022-11-05 15:37
One thing that will probably interest you is [General](https://github.com/noctuid/general.el). It's a keybinding manager that provides, among other things, vim-like remapping.
jmite · 2022-11-05 15:39
If you disable all the modules in doom that you don't want then it's very lightweight.
aminevsaziz · 2022-11-05 15:52
That's essential to enable evil in emacs.
cmagnificent · 2022-11-05 15:53
The three I mentioned allow you to set completely custom bindings. I think some of their examples on their pages might not do much other than use 'C-' less, but you can set the bindings to your preference. My set up does try to follow vanilla emacs muscle memory for the most part, but I could have just as easily set up hjkl, made 'd' a prefix key for a map that holds relevant entries for things like 'w', so 'dw' would delete the word, or 'dd' would kill the line, etc. You can set it up however you want; if that's a more substantial change than just using 'C-' less often, that's possible.
thriveth · 2022-11-05 15:53
As already mentioned, the first and foremost thing to do is install evil-mode. There are also a bunch of extras that are all called evil-something in the package manager (M-x list-packages), I recommend reading through them and seeing if they look like you need them. Do not install too many of them all at once though, it can get confusing and break things. For Leader-key functionality (Space key in Doom), there's a package called evil-leader, although I use General.el because it can do the same thing as evil-leader and a bunch more, so I can keep all my keybindings in one place.
aminevsaziz · 2022-11-05 15:55
That package saved me headaches. But the issue is the keybinds lacks a clear template for us newcomers to work on it.
aminevsaziz · 2022-11-05 16:23
Can you share your keybinds?
aminevsaziz · 2022-11-05 16:23
Can you share your setup?
thriveth · 2022-11-05 17:31
You can find the majority of my keybindings and associated Evil set-up here: https://gist.github.com/thriveth/1cfb03fac55c3076a34f9627bc3c6a63 I don't promise it works by simple copy-paste (actually I can pretty much promise it will not), I just extracted the relevant parts of my config into a separate document, but it's somewhere to start from.
cmagnificent · 2022-11-05 17:40
Eh, potentially embarrassing, [here it is.](https://github.com/cmagnificent/cmagn-emacs/blob/main/cmagn-modalka-config.el) Things that are *opinionated*: Going through the process of setting it up, I was convinced of the validity of multiple criticisms around modal editing in emacs, because I had to go through and consciously think about what I wanted out of modal editing and how best to facilitate that within emacs. What I landed on was the fact that read only mode already did about a third of what I wanted, so my modal editing was going to be pretty minimal, focused on movement not necessarily having as many commands at a single keypress as possible, and to highlight and make aggressive use of the already powerful point and mark functionality. The result of that is that my 'insert' mode is just vanilla emacs, as is, the only binding is `C-;` to toggle modalka, which doesn't have a binding by default. *Every vanilla emacs key binding and command will continue to work in modalka mode.* For the movement keys, I am not convinced that hitting shift all the time with the pinkies is better than hitting alt with the thumbs, and luckily for me `M-n/p` aren't bound to anything by default, except to scroll up/down in things like the kill ring, so it is already a vanilla up/down motion, emacs' internal semantic scheme prefers the `M-` prefix for natural language objects like paragraphs, and this frees up all of the other movement keys to work with shift selection to support the idea of the visual/normal mode hybrid. `;` \- For exiting modalka back to regular emacs, symmetry with `C-;` and on the home-how. Same logic applies to `'` and `"` for beginning/end of line and exit modalka. `r` \- For replacing a character under the point, kind of a core thing for modal editing, and I-Search can be called normally, and then reversed within I-search using `C-r`, so it seems a fairly non-intrusive binding. `d` \- Will kill a region if one is active, and will otherwise delete the character under the point, so I bound `w` to copy (M-w) instead of mimicking it's `C-` prefix behavior. `.` \- Dot to just points to another map that puts a whole bunch of mark and point controls at easy access, next to `SPC` which activates the mark and `,` which does the point and mark switch. Things that are *ugly*: The recommendation on the modalka page for a cursor change involves setting the cursor type to bar globally, and setting modalka to box, but I do not want a bar cursor in the rest of emacs (dired, buffer-menu, etc). I have no idea why I have to write the cursor change in reverse of what my intuition would tell me to do to get the change to only apply in modalka, so we can go ahead and call this one an "empirical" solution. Though this empirical solution does let me set it for the minibuffer for visual consistency there. The `C-c` prefix map does not work like other keymaps in emacs. In short, it's a dummy that points to other maps, which makes it tricky to bind. I eventually found a function to just simulate a keypress, and bound that. This adds a lot of overhead to the action of the keypress (that one would almost certainly never notice in any meaningful way on modern hardware) and it's kind of a sledgehammer, but it works, to be used sparingly. By default, modalka does not interfere with any key presses, which is useful in the case of backspace and return which I still find useful in modalka mode, but it also means that everything I don't want to use and don't want to accidentally self-insert when I press it has to be set to nil, which is the actual reason my config is longer than the modalka package. Otherwise it's just close, lol. In true emacs fashion, thanks for justifying something I put *way* too much thought and time into for a relatively simple solution by asking the question.
aminevsaziz · 2022-11-05 18:43
That's good start ☺️
aminevsaziz · 2022-11-05 18:45
That's more informative about modlka than the package readme. Having an example help understand the overall concept.
cmagnificent · 2022-11-05 19:07
I think there are some language barrier issues happening with the readme, but the intention with modalka is that it's supposed to be very minimal, and entirely customized from the bottom up. That level of set up isn't going to appeal to everyone, but I found the whole thing pretty rewarding, again because it made me really think about whether or I should change things just for the sake of change.
Top-Egg-16 · 2022-11-06 08:37
Modalka looks like good stuff, thanks!
AniketGM · 2022-11-06 10:33
Follow DT's [config](https://gitlab.com/dwt1/dotfiles/-/blob/master/.emacs.d.gnu/config.org) He also has a YouTube channel. DistroTube.