The extensible vi layer for Emacs
github.com
github.com
I like vim as a touch typer, I think it's a setting that minimize end motions. It's also very convenient in the terminal. On the other hand, I think it's not convenient as an IDE: too many shortcuts, clumsy integration with LSPs, especially when you need to work with different languages.
For me it works best as a light, universal, editing mode on top of a modern solution for an IDE. That being said, I wonder if I wouldn't be better off moving away from vim entirely and get used to a simple setting which works straight out of the box.
That's a surprising sentence to read, as someone who's also used to vim (although I've moved from vim to emacs+evil and not the other way around).
I have some gripes with my emacs+evil setup, just as I had some gripes with my vim (and then neovim) setup. But none of those gripes were related to the actual text editing, but rather making those tools behave like an IDE.
For the modal text editing, after I got used to it, I have zero complaints, and I feel much more comfortable editing any sort of text/code that way.
If I had to choose, I'd rather give up syntax highlighting than modal editing, because it has become so ingrained.
Well, I feel modal editing is "comfortable", as in easy on the fingers. But overall, I'm also quite fluent with the mac os shortcuts. Maybe it's just a matter of learning the few things I don't know how to do without vim and I'd be equally happy. The added bonus would be to have a simplified set up that would work in every contexts where vim isn't available. That being said, it's not something I want to do actively as I'm happy with my set up, but just wondering if the benefit is real.
For local development I use Webstorm, Rubymine, intellij etc. with IdeaVim, this is mainly because I prefer not fiddling around with plugins and configs I want my IDE to “just work” no matter what language I am using.
For writing project plans, design docs, etc. I used to use spacemacs for org mode with vim integration but now I have found myself switching to Obsidian (which has vim keybindings) and I have been dabbling in Quarto with VSCode but I haven’t settled on a good workflow.
Spacemacs is also nice because you can use magit if you want. But I don’t recommend using eMacs or vim as your main IDE because, like you said, the auto complete tools like intellisense and GitHub copilot integrations in other IDEs just work a lot better.
I generally now just feel like I want my development environment (laptop, ide, shell) to “just work” I want to spend as little time as possible configuring that stuff and I just want to focus on actually building stuff.
It's a real turn off that a commercial IDE can't get fundamental stuff like the one show in the bug tracker correct (or fixed in a timely manner). You start to question why you are even paying for the thing.
The way I see/read it: it _isn't_ being used in respect to nothing _reads_ it, except within the calculation to raise - there's nothing that reads the result of the raise. It's warning you that you are (potentially) needlessly capturing state. I agree it's a valid warning (for that specific example.)
I appreciate it is just an example to demonstrate the issue but I am unable to deduce a scenario where that wouldn't be a valid warning.
I asked for two things which are conceptually much simpler:
1. a project manager/file explorer solution (file browser plugins have always been super popular for Vim; plus Sublime, VS Code, etc, all offer file explorers, they're extremely useful for... exploring projects for folks.
2. moving the command bar at the top
And they were both closed as WONTFIX mentioning that the Neovim core is meant to be compact and everything else should be built on top.
So that would require someone making and maintaining a super popular Neovim "distribution". I'm not saying it won't happen, but both in the Vim world and the Emacs one it doesn't seem like any distribution "won out" and you're always worried your distribution will just go away at some point.
The command/status bar pops up in a modal akin to ctrl+p in vscode.
Not all plugin work, mostly the esoteric ones that spawn many buffers etc, but all your motions etc work fine.
Personally I find vscodes text rendering not as nice as alacritty for what ever reason, otherwise I would probably use it as my primary interface.
In other words, I like to have 1 LSP installed in my system for all of them.
But the killer feature is meow's macro system
I’ve patched the boon code to support switching between Dvorak and QWERTY
I've since switched to god-mode [0], which just turns emacs keybindings into modal ones. I find it works quite well. I think emacs keybindings are easier to remember but harder to use. Turning them modal solved that for me. (For example, Ctrl + F for forward, Ctrl + B for backward is easy to remember, but hjkl is right by your fingertips).
Side-note, it looks like god-mode was archived and then made part of the emacs orphanage. I started using it years after it was archived before it was part of the emacs orphanage. Noticed no issues, since again all it does is just make emacs keybindings modal.
Mentioned elsewhere here, I've found meow[1] to be really interesting/good. And it leverages some of what makes god-mode nice (from their list of key features: "Minimizes modifier usage (e.g. `SPC x f` for `C-x C-f`) inspired by god-mode")
[0]: https://github.com/emacsorphanage/god-mode/commits/master
- use evil-collection or
- be prepared to design vim keybindings per mode or
- instead use https://github.com/meow-edit/meow
I'm still waiting for JetBrains to wake up from sleeping at the wheel and implement a Neovim client for their IDE core.
Most vim emulation plugins struggle with accuracy, EVIL exceeds it. Manly due to evil-collection and various other packages, pretty much every emacs package has evil support, and that integration feels very native to emacs
This is a case where being a neovim gui would be worse. Though, someone could totally do it for shits and giggles.
Finally, that operating system would have a decent text editor :)
- global undo tree
- the " and * registers work very differently than in vim, but there's a setting to fix it
I don't get it, if you are targeting developers, why is it that having Vim keybindings not a top priority? Or am I living in my own circle?
There's an interesting blog post from a recruiting company breaking down the data they have on editors and developer success in their interview process. https://triplebyte.com/blog/technical-interview-performance-...
Personally I just use Jetbrains IDEs w/ IdeaVIM for most things because I can’t be bothered with all the plugins and configurations I would rather my IDE just work out the box in any language.
I fully agree with you. I'm not sure why they're asleep at the wheel.
I grew up using Emacs—I think the first time I fired it up was when I was about 7 and was learning how to use mutt to read and send email. I used Emacs exclusively—I did learn the basics of vi bindings but never seriously used it—until I was about 24. I got a nasty case of RSI from using a mouse too much for too long. I went all-in on my ergonomic setup: I got a split/tented keyboard, a standing desk, went to physical therapy, etc.
I also took a look at my keystrokes and decided to 1.) get a keyboard with a thumb cluster so I could put modifier keys on my thumbs, and 2.) switched to Evil mode for the Vim bindings.
Life is awesome now.
I believe Emacs+Evil is the best of both worlds. I initially poo-pooed modal editing (why do I have to distinguish between inserting and appending?! It's so stupid!) but I've relented—using Vim bindings is like having a little composable language to talk about text editing. It's amazing.
Evil is incredible too. I'm still tweaking my setup to this day. But that's the thing—I like being able to tweak my setup to get to the maximum ergonomic configuration for me. I think there's some room for some better defaults and/or starter kits in this space (e.g. switching to vterm-mode should automatically take you out of Evil and drop you into the normal Emacs bindings, etc.) but things like evil-collection makes it so that I don't have to switch in and out of Vim-movement thinking.
Some things that switching to Evil-mode feasable:
- I started using the GUI so that Emacs could distinguish between e.g. Ctrl-Shift-x and Ctrl-x—it's nice having richer modifier combinations at your disposal.
- Having Ctrl-z bound to `emacs-evil-state` is a life-saver in situtations where you want to switch back to Emacs bindings for whatever reason.
As I understand it, Evil is the best Vim emulation out there bar none. E.g. I can use `/` as a motion command: `c/foo <RET>` will delete from the point to the next occurrence of `foo` and put me into insert mode. All this without loosing any of the customizability and the larger package ecosystem of Emacs.
Learn to use multiple cursors in Helix - many of the things I have found lacking from Vi - eg pressing . doesn't work the same way in Helix - can be made up with more or less by using multiple cursors.
This switches most keybinds to be vi-like.
I've never used it to emulate vi but I have used it to emulate ex, which is a part of vi. I don't know if anyone else feels this way but when I started with emacs a long time ago I thought that ex commands were much more productive for things like searching and replacing. For anyone who knows vi, that is for example :%s/regex/replacement/
So I just bound the ex prompt to C-c :
Maybe emacs does better for search/replace these days. What do others think?
However the incremental search (C-s) of Emacs goes much further than that. It is packed with features. While it has too many features to enumerate in one comment, I'll just pick one thing about it that I have found useful and quite enjoyable. It is the set of various toggles Emacs incremental-search comes with. Some of those toggles turn out to be very useful in special circumstances.
Say, I have a source code file that is doing some regex-based work. Both the regex "f.." and the strings it matches like "foo", "fox", etc. occur in the file. Now say, I want to search for the regular expression pattern "f.." (not the strings it matches). I can of course do that simply with:
C-s f..
After searching for that regular expression, I decide that I now want to search for strings that match the regex pattern "f..". Now I can simply change the string search to regex-based search with this toggle: M-r
As another example, let us say, I start searching for the string "web_server" with this key sequence: C-s web_server RET
But then I realize that the current code has the words "web" and "server" written together in all kinds of notation like "web->server", "web::server", "web-server", etc. and now I want to match all of them. In Vim, I would have to cancel the current search and write a new search expression, perhaps something like /web.\{1,2}server or maybe /web[-_:>]\+server depending on what we need. In Emacs, I can do it with this toggle: M-s w
And now it would match "web->server", "web::server", "web-server", etc. I know you specifically mentioned search-and-replace, not just search. The conveniences I illustrated above are available equally well in search-and-replace too because converting a currently ongoing search to search-and-replace in Emacs is yet another toggle: M-%So (add-hook 'find-file-hook 'start-view-mode) to turn it on automatically.
(defun view-mode-background () (if (bound-and-true-p view-mode) (face-remap-add-relative 'mode-line '((:background "#9400D3"))) (face-remap-add-relative 'mode-line '((:background "red"))))) ^ this helps a lot to know whether or not you're in view mode
And then: (defun view-mode-keybindings () (define-key view-mode-map (kbd "j") 'View-scroll-line-forward) .. etc
> To be most effective, Vim should be used from inside other tools. Vim inside IntelliJ, Vim inside VS Code.
> In whatever tool you’re already using, if you want a better editing experience, add Vim to it.
> To be very clear then, Emacs users: Rock on. Be happy.
So, Vim inside Emacs a.k.a. The extensible vi layer for Emacs.
In the future, can neovim match and exceed emacs? yes. Is it capable of it? yes.
It however, is not currently is not an emacs replacement in any way shape or form. It is an entirely different editor, with a different way of going about things, and should be treated as such.
This is coming from someone who often contributes to neovim and neovide (a neovim GUI), and uses fennel both inside and outside of neovim extensively.
If someone told me to change my workflow just to use the same bindings, that gives me every reason not to do it more.
(Edit: Turns out I do remember some of the annoyances. See the grandchild comment below where I have noted some examples.)
I found Evil mode is so much better at emulating Vim than viper mode.
emacs -q
M-x viper-mode RET
Chose expert level 1 for beginners so that it is closest to Vi behavior. (Recommended level is at least 3 but that does not make a difference for what I am about to explain.) C-x C-f foo.txt RET
i
hello world RET
hello world RET
hello world RET
ESC
Looking good so far. gg
Does nothing!! Okay no problem. Let me try: :0 RET
Good. I am back to the top line. V
Instead of starting visual line mode, it brings up find file minibuffer.So that's 2 problems already from 2 minutes of using Viper. I have to admit though that I come from Vim (not Vi) so maybe my expectations are not fair for Viper. Is gg a Vi command or Vim? I can't remember. But I expect these basic things to work. It is this kind of stuff that used to trip me up often that I discontinued Viper and went with Evil.
BTW this list of annoyances in Viper keeps going on and on.
- dab, da(, di(, dib, etc. don't delete a block.
- gqq, gqgq, etc. don't reformat paragraphs.
- * does not search for the current word
- and so on and so on
Maybe I am being unfair to Viper but I guess you can see why in 2023, a Vim user might want to skip Viper completely and go straight to Evil.
Yes, I can see why, if you require all of these vim features, viper would not be good for you. "Viper mode is terrible though." was not a good way to express this. The title of the thread, and the name of the package (incorrectly) state that it is a vi layer, so it's natural to mention the vi layer that's built into Emacs. It's definitely something that people should remain aware of and still provides value. IMO, Emacs + viper is significantly better than just Emacs, so it's worth knowing about. Comparing its vi functionality against vim is definitely good, but it being forgotten and neglected is not.
Agreed and thanks for calling it out. Will be more careful next time.
Prior to evil-mode, when I used emacs for something, I used it without viper because at least then it was so very different that it didn't trick my subconscious into doing something that wouldn't work.
With a few tweaks to my config, I never have that problem with evil.
Agreed! Fixed that. See sibling comment of mine.