Hacker News new | past | comments | ask | show | jobs | submit login
Devil Mode for Emacs (susam.github.io)
143 points by susam on May 15, 2023 | hide | past | favorite | 78 comments



Even better idea: How about if you pressed the comma, it would temporarily cause all subsequent keystrokes to be interpreted as if with the Ctrl modifier? Then you could press another key to go back to inserting text. In fact, the editor could even start in the “comma” state because usually after opening a file, you want to first navigate around before inserting text. And to allow typing commas easily, we could just use the escape key instead. I'm sure no one has ever thought of this before.


The idea that a comma is nearly always followed by space or new line, and can therefor be useful is pretty genius though.

A few years ago someone mentioned they map "jj" to escape in vim and I've been doing it ever since. Have you ever had to type two j's' next to each other? I haven't in several years now. :D Only problem is inserting a dozen 'j's before I realize what's going on when I'm on a remote machine...


["string","string"] and [1,2], that is comma-quote and comma-number are both fairly common. Granted ModKey-(#|") is also pretty unlikely to be a command


I always put a space after a comma in an inline array, personally.


I often don't. Let the formatter do that. Why waste keystrokes on formatting?


Hey now … you’re describing vi ;)


That's the joke


I know. It’s a very good joke.


Sounds too modal. I'll be forever toggling back and forth.


Devil is non-modal. As soon as you type a complete key sequence, Devil executes the command and gets out of your way. There is no toggling back because Devil deactivates itself automatically on command execution. And then Devil remains idle until you type the Devil key again.


I believe this was their point, see gp


The advantages of modal systems are more apparent once RSI gets to your wrists.


Well, not me; I moved the modifier key to a foot pedal.

("It's free real estate..." ;) )


Way to get your daily steps in…


You have just described Hydra:

https://github.com/abo-abo/hydra


Devil is more like god-mode than Hydra. Hydra is useful for defining your own nested menu of key-bindings. Devil, on the other hand, lets you use the vanilla Emacs keybindings using a different “notation”. This is pretty much what god-mode does too. However god-mode is modal but Devil is not.


If this sounds interesting, make sure to check out Spacemacs[0], which uses a similar principle (tapping a leader key - space), but transforms the editing experience in a much more radical way (evil-mode and such).

I've used Spacemacs for a while, and was quite happy with it, but I wanted a more lightweight editor for the terminal, something I can use on servers and embedded devices without installing an entire Emacs and a zillion packages. So my Emacs setup is much more standard nowadays, and I use mg[1] otherwise.

[0]: https://www.spacemacs.org/

[1]: https://man.openbsd.org/mg


Also Doom Emacs, which is really stable (pins dependencies), fast and has great defaults:

https://github.com/doomemacs/doomemacs

Also, don’t use pinky for controls —— home row mods all the way.


I recommend Spacemacs for beginners, but I did end up switching from Spacemacs to Doom Emacs primarily for better stability, and haven't regretted it.

They're both good projects.


I started with Spacemacs as my intro to Emacs (coming from VS Code, learning both Vim keybinds and getting the power of Emacs was very intriguing), and I think Spacemacs is much better for total beginners. I eventually felt comfortable enough to move to Doom Emacs and start writing my own config additions, which Doom is much better for imo.


I haven't used other configuration frameworks, so this may exist elsewhere, but really appreciate dooms cohesive configuration scheme.


Switching from Neovim to Doom Emacs has been such a pleasant experience.


I made the switch a few years ago now, evil-mode is amazing since essentially every vim operation can be used while I also can leverage the massive amount of emacs functionality and packages.


And vice versa :)


I use both, often I'll use nvim if I'm already in a terminal and want to edit a file quickly. Having two editors, emacs and neovim, which have essentially the same keybindings is very nice since it let's me be more dynamic.


Not an emacs user (sadly), but worth pointing out that one can map modifier keys to other input devices like pedals. It is very helpful if you are dealing with RSIs affecting your hands.

(Admittedly, pedals work well only in a desk scenario. I can't see myself logging them to a cafe.)


can confirm the fast part. Doom Emacs was the first time a pre-packaged editor was much faster than my laboriously handcrafted init file and I was really salty about it. It's a solid project to try out even if you know your way around emacs.


Doom has spoiled me. I started with doom since I was coming from neovim and heard it had good defaults, not whenever I try to start building a config from scratch it's very difficult since I'm so used to the out of the box experience.


> Also, don’t use pinky for controls —— home row mods all the way.

Is that just personal preference or is there some reason to avoid pinky control?


FYI, you can use your local emacs to edit remote files via TRAMP.

Vim also has this feature built-in: :e scp://user@host:port//path/to/file

This way, your config can live exactly where it should: on your local system.


What of Git plugins, linters, make programs? The environment is on the host, not your laptop or whatever. There is no way around that.


If you have the language server installed remotely LSP mode works via Tramp, too:

https://emacs-lsp.github.io/lsp-mode/page/remote/

Best to add the language server to your application’s runtime anyway.

But for magit or vc you’ll need a remote git and repository, yes.

In my case, I can actually do quite a bit of exploratory debugging using my local Emacs editing files on a copy of the production setup via ssh. I am also leveraging compile mode to run scripts restarting test servers this way.


I guess we prioritize different things. I get annoyed with local intelligent autocompleters for being variable in both what they find and when they find it. I can’t imagine adding a network connection to that equation will improve anything.

I use keyword completion. It always works, it’s never “wrong” or misconfigured, and it’s easy to predict what it does. Just my 20 m$.


Well, you can still have that too.


Not quite true, you can get magit to work through tramp and you can tell emacs how to run other process that are remote too.

But if the status quo remains as it was in 2022 when I last used codespace, it is a lot of configuration and there might be some things you need to turn off (like for me git-gutter) to get a tolerable experience.


Yep, tramp handles all that. It's pretty amazing


I knew someone would mention tramp ;) I tried it but found the experience lacking. I would rather have a consistent and predictable feature set in a lightweight package, which (for things that I use it for) mg delivers.


There's also spacevim:

https://spacevim.org/

And to a certain extent the new Helix editor which uses space and context sensitive popup menues for discoverability to great effect IMNHO:

https://helix-editor.com/


One of these days, I will get around to making the ultimate emacs UI: zero defaults.

Give me a way to set and organize keybinds, good documentation, and nothing else. Every time I need a new keybind, I must explicitly decide what it will be. Inconvenient? So is learning the default, or worse, figuring out how my unique config accommodates that default.

It would be more work now for less work later. It would also move the work of UI/UX design into the same step as UI/UX learning; which I consider the most sensible place and time to do that work.


That sounds really neat. I spent a couple weeks trying to publish all my notes using org-mode, and it was pretty frustrating to find all these key bindings on the net that didn't actually work in my setup. A bare setup where you could opt-in to keybinding "packages" with a global way to see conflicts would be cool.


It's been a pet idea of mine for a while, but every time I have tried to implement it, I have gotten tripped up on some UX design decision, or some fundamental, but poorly documented, part of the codebase.

My dream is a doesn't-resemble-vim modal editor from scratch. When I want more functionally, I will give it an intentional home in my normal mode config.


At its core, both Spacemacs and Doom Emacs are configuration frameworks. If you remove all the default packages/layers, you end up with a way to organize all your custom configs, and nothing else.


And under the hood they are complicated wrappers around use-package. With good reason, of course, but that reason doesn't really exist when you aren't using the distribution's configuration packages.


This sounds way more inconvenient to me when you figure in the amount of mistakes you are going to make creating keybindings in the fly. What might make perfect sense at first will seem really dumb once you've added 20 more shortcuts, and then you'll have to either stick with it or start over and relearn.

And seriously, emacs does so much! You won't even know what you don't know if you don't use the work others have done creating the UI (keybindings and shortcuts). Unless you really want to read all the source code yourself too


> mistakes you are going to make creating keybindings in the fly.

I have no clue what you mean. What is a mistake? In the fly? I'm talking about my permanent (until I intentionally change it) config, not some temporary real-time thing.

> What might make perfect sense at first will seem really dumb once you've added 20 more shortcuts, and then you'll have to either stick with it or start over and relearn.

Yes, but the alternative is starting with someone else's mistakes. I would rather deal with my own, because at least then I know what they are.

> You won't even know what you don't know if you don't use the work others have done creating the UI

Isn't that the status quo? If you want to use an unfamiliar feature, looking up the default keybind should be no easier than looking up the function itself.


As someone who works on many different machines during the day the defaults are the only thing that matters. Moving your environment around to every machine you touch is completely impractical and in some cases straight up disallowed by the rules of the lab.


I used to think this way until I spent some time working with and tuning my TRAMP setup. Now that Eglot is shipped with Emacs 29 I've switched from lsp-mode, and lo and behold, dealing with remote LSP servers is a lot easier.

I was a hardcore terminal Emacs and tmux user, but have since switched to GUI Emacs and multi-vterm and was able to retain much of my tmux muscle memory. I now am routinely editing files on a handful of different machines every day, and it's mostly great. I still have to call tramp-cleanup-all-connections to deal with the occasional hangs after a few days of idle time, but I'm pretty happy.


Thankfully for me, 9999/10000 times, I'm using my own system. On the off chance I am using someone else's system, I probably won't be doing anything particularly interesting or staying very long. On top of that, I can usually bring my keyboard, which itself contains most of my divergence from norm.

If customisability were really as available as it should be, it would be trivial to change between configurations. After all, the only technical hurdle is that most software is built on UI/UX assumptions.


There's also Meow[1], which I currently use. You have to configure it first to suit your keyboard layout, but there are pre-built configs [2]

[1] https://github.com/meow-edit/meow

[2] https://github.com/meow-edit/meow/blob/master/TUTORIAL.org#k...


It's really cool how emacs has created such a great diversity of control key systems. I use the defaults because I don't use home row, but what a wonderful and powerful experience that users have been able to gather together and create such ecosystems. Thanks Emacs, and here's to many more years with you and many more audacious ideas like this one.


> It's really cool how emacs has created such a great diversity of control key systems.

It's really cool, to say the least. Ive been seriously considering using emacs as a base for building a UI for a project I'm planning that is heavily text based, would be useful since I could define a default keymap and leverage emacs to allow advanced customization without having to clutter the base user experience.


> I use the defaults because I don't use home row

That's funny, I use the defaults because I do use home row. That said, I do use Dvorak, so that may explain why things seems to work better for me than the average other user.


Eh, good timing. I just migrated my config to evil.

I gave the Emacs keybinds a year long chance, got a split keyboard with Emacs-friendly custom keymap (Alt under my left thumb, Ctrl under my right thumb) and life was pretty good, but I can now say that vim editing is hands down better than any Emacs incantation.

That said, vim+Emacs together are even better than each in isolation. Nothing beats modal editing, with access to C-a, C-e, and other Emacs movement keys to be used in INSERT mode. The default evil config should promote this hybrid approach, rather than trying to turn Emacs into vim.

Devil mode looks interesting, but still not as good as a true modal experience.


Having used emacs for 20-ish years, this actually looks amazing. If you didn't RTFA, this is not another vi mode. This replaces holding down Ctrl with tapping comma to get all of emacs' keybindings. It is incredibly clever in the way it does it and I can't wait to try. I think it will make using emacs more ergonomic with regular keyboards and much more so with a phone touchscreen.



Love the idea! Gotta try it, to give my poor Emacs pinky a rest.

I also like the audacious stealing of a common key like COMMA.


You might also find https://web.archive.org/web/20130512065149/http://www.andong... interesting. The theory is that since you only ever have a space after a comma, you can use it as a dead key, and just have ", " output ", ". That then frees all the other letter combos to be whatever key you want.

There are other keyboard layouts out there with the same concept too: https://github.com/workman-layout/Workman/tree/master/mac#wo...


Mode-specific comma key actions are something I never knew I wanted coming from other editors.


Remap Caps Lock to Ctrl.


YES, BUT IT MAKES IT HARD TO YELL AT PEOPLE, AND THAT'S HOW I SPEND MOST OF MY TIME.


I have an additional Ctrl on the CapsLock key, and use Both Shift keys to toggle Caps Lock mode - best of both worlds!

     setxkbmap -option shift:both_capslock -option compose:rctrl-altgr -option ctrl:nocaps  -option lv3:ralt_switch


I am not quite sure what this says about me but I LMAO looking at this one, thanks


Do you not use your pinky to hit the caps lock key?


The Caps Lock key sits a few millimeters away from where my pinky rests on the home row. The Ctrl key is a full inch away.


As described in the Devil manual, you can make the semicolon the active key instead of the comma--you don't even have to leave the home row to trigger commands.


this is the way


Spacemacs for the rescue.


Kudos for the very thoughtful write-up explaining the choices between particular mapping decisions.


On Linux and macOS I change Capslock to Control in the settings. On Windows I download Power Toys and do the same thing. Makes Emacs so much more useable


It didn’t take me long to start getting hand pain from using Emacs when I started using it a lot. I considered learning the technique of using the ball of my hand to press control. But instead of switching to vi it getting an Emacs hand brace, I ended up switching to a keyboard where I had modifier keys on my thumbs. That was like five years ago and I’ve been fine since then.


My controls are handles by my thumbs (Kinesis Advantage) and I fail to see the advantage here as you are using the same amount of energy, but fail badly for cases where control could have been held down (eg. compare Ctrl-down p-down p-up p-down p-up Ctrl-up to ,-dn ,-up, p-dn, p-up, etc).


I use a kinesis at work and I hate hate hate the placement of Alt. I always have to move my hand entirely and stretching from alt to x is unergonomic and annoying.


The first thing I did (28 years ago) was to remap Delete and Alt, swapping them, pretty much a necessity if you are an Emacs user. On the standard keyboard it's literally just Prgm Del Alt Alt Del Prgm. However I have since replace the keyboard controller and use my own firmware now in where the swap is hard coded.


you can easily remap it??


Every bit of this horrifies me, and I can't believe you've done it.

Outstanding. Well done!


It should have "Show HN" in the title.


I don't understand wny.


Agree this is like how to play tennis with a baseball bat.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: