Switching To Emacs as a Neovim User

Switching To Emacs as a Neovim User

从 Neovim 用户转向 Emacs

I have always liked the idea of having one program to do everything on my computer. Also, I have always been a fan of text-based interfaces. These two preferences of mine scream Emacs user, but I have never really used it seriously. My experience with Emacs has only been installing it every once in a while, opening it up, failing to understand how it works, and then uninstalling it again. So why switch to Emacs now?

我一直很喜欢“用一个程序完成电脑上所有事情”的想法。此外,我一直都是基于文本的界面的忠实粉丝。这两个偏好简直就是 Emacs 用户的典型特征,但我从未真正认真地使用过它。我过去对 Emacs 的体验仅限于偶尔安装一下,打开它,发现完全看不懂它是如何工作的,然后再次卸载。那么,为什么现在要转向 Emacs 呢?

What I Was Missing in Neovim

我在 Neovim 中缺失了什么

I have successfully been using Neovim for quite some time and was very happy with it. The thing is, Neovim is meant to be used as a text editor, and to be frank: it excels at that. I love everything about Neovim: the ergonomic keybinds, the package system, the customizability, everything. I have been using it for software development and have had zero issues.

我使用 Neovim 已经有一段时间了,并且一直很满意。问题在于,Neovim 的定位是文本编辑器,坦白说:它在这方面表现得非常出色。我喜欢 Neovim 的一切:符合人体工程学的快捷键、插件系统、可定制性,应有尽有。我一直用它进行软件开发,从未遇到过任何问题。

One concept I was always fascinated by was text-based browsers like lynx. Just being able to access all the information the web has to offer from my terminal felt like a great idea. In practice, of course, many modern web pages do not accomodate for browsers without javascript support, but that is besides my point. Another idea that sparked interest in me was reading emails from the terminal. Or having a calendar in the terminal. Or chatting on IRC channels from the terminal. Basically, I love the terminal.

我一直对像 lynx 这样的文本浏览器很着迷。仅仅通过终端就能访问网络上提供的所有信息,这听起来是个很棒的主意。当然,在实践中,许多现代网页并不支持没有 JavaScript 的浏览器,但这并非重点。另一个让我感兴趣的想法是在终端里阅读邮件、在终端里查看日历,或者在终端里进行 IRC 聊天。简而言之,我热爱终端。

So what ended up happening was that I had all of these different programs to do different things. That was fine and it worked well, but each program had their own keybinds and conventions and things to be aware of. Neovim was just that: one of the many programs I used. I just used it to edit text files. I would have loved to have a program like Emacs that would compile all of these utilities into one large piece of software (I am aware that much of the functionality I mentioned is achieved through packages in Emacs, but I am mainly referring to having one large ecosystem to do all of those things rather than one literal codebase that does it).

最终的结果是,我不得不使用各种不同的程序来完成不同的任务。这虽然可行且运行良好,但每个程序都有各自的快捷键、约定和需要注意的事项。Neovim 仅仅是我所使用的众多程序之一,我只用它来编辑文本文件。我非常希望能有一个像 Emacs 那样的程序,将所有这些工具整合到一个大型软件中(我意识到我提到的许多功能在 Emacs 中是通过插件实现的,但我主要指的是拥有一个能够完成所有这些事情的大型生态系统,而不是指一个字面意义上包含所有代码的单一程序)。

Why I Went With Doom Emacs

为什么我选择了 Doom Emacs

When it comes to Emacs, I am very much a beginner. I am not a fan of using premade configurations for whatever software you use - whether we are talking about a window manager like i3 or Hyprland, or a text editor like Neovim. In fact, my Neovim config is written by me and has exactly what I need. Another nice bonus of doing this is that I know how everything works. This means that, should something break, I would be able to fix it. Or, if I need to add something to my config, I would know where to look.

谈到 Emacs,我完全是个新手。我不喜欢使用任何软件的预设配置——无论是像 i3 或 Hyprland 这样的窗口管理器,还是像 Neovim 这样的文本编辑器。事实上,我的 Neovim 配置是我自己写的,里面只有我真正需要的东西。这样做还有一个额外的好处:我清楚一切是如何运作的。这意味着如果出了问题,我有能力修复它;或者如果我需要添加新功能,我也知道该去哪里修改。

Now, if I look back at my Neovim journey, I have also experimented with prebuilt configurations for Neovim. If anybody knows about them, I have tried LunarVim (which I used for quite a while) and NvChad. Eventually, once I got comfortable with Neovim and figured out what I used frequently, what was left unused, and what I needed, I proceeded to write my own config. It’s not like I did not try to use vanilla Emacs, but I just could not do it. I got some basic things working but it was taking such a long time that, at this pace, it would have taken me literal months of work to get to a point that would allow me to completely switch over from Neovim to Emacs even for my job.

回顾我的 Neovim 之路,我也曾尝试过预构建的配置。如果有人了解的话,我试过 LunarVim(用了相当长一段时间)和 NvChad。最终,当我熟悉了 Neovim,弄清楚了哪些是我常用的、哪些是多余的、哪些是我真正需要的之后,我开始编写自己的配置。并不是我没尝试过原生 Emacs,但我实在搞不定。我虽然让一些基本功能跑通了,但耗时太长,照这个进度,我可能需要几个月的时间才能达到能够完全从 Neovim 切换到 Emacs 并用于工作的程度。

This is the reason why I decided to go with Doom Emacs. On top of all the reasons mentioned above, in my research it seemed to be the case that Doom Emacs is ideal for people coming from Neovim, like me, since it uses Vim keybinds for everything. I can definitely confirm that Doom Emacs has eased the transition significantly and I could get up and running fairly quickly.

这就是我决定选择 Doom Emacs 的原因。除了上述所有理由外,根据我的研究,Doom Emacs 对于像我这样从 Neovim 转过来的人来说非常理想,因为它在所有地方都使用了 Vim 快捷键。我可以肯定地说,Doom Emacs 极大地简化了过渡过程,让我能够非常快地上手。

Some Things I Like About Emacs

我喜欢 Emacs 的一些地方

Since the built-in package manager has been introduced in Neovim, this is not as true anymore, but when I first started using Neovim, this very much did apply: with Emacs, installing new packages is incredibly easy. As long as you stick to the built-in repositories for Emacs packages (which are rather extensive), you can just do M-x package-install and install a new package. Everything is done automatically. This felt so great to me. It was a breath of fresh air compared to what I was used to.

自从 Neovim 引入内置插件管理器后,情况有所改变,但在我刚开始使用 Neovim 时,这一点非常明显:在 Emacs 中,安装新插件极其简单。只要你使用 Emacs 的内置仓库(这些仓库非常丰富),只需运行 M-x package-install 即可安装新插件。一切都是自动完成的。这让我感觉太棒了,与我过去习惯的方式相比,这简直是一股清流。

Also, the setup required to get language servers working (especially before the introduction of the built-in lsp integration that modern Neovim ships with) is minimal compared to Neovim. Language servers and syntax highlighting have become a central part of my workflow when programming, and I believe that every serious editor that strives to gain traction should support TreeSitter and LSPs easily and (ideally) natively.

此外,与 Neovim 相比,配置语言服务器(尤其是现代 Neovim 内置 LSP 集成出现之前)所需的工作量微乎其微。语言服务器和语法高亮已成为我编程工作流的核心部分,我认为任何想要获得发展的严肃编辑器都应该轻松地(最好是原生)支持 TreeSitter 和 LSP。

Also, another thing I thoroughly enjoyed in emacs is the extensive documentation. The documentation emacs has is not even comparable to the Neovim help pages. With emacs, you can easily figure out what a certain key combination does, or what key combination you need to press to trigger a certain command. You can easily search what commands there are via keywords. It is just so great. With vanilla emacs you could even press C-h m and it would open a list of all the possible actions one can take in that particular scenario (for those familiar with emacs, with “scenario” I mean major mode).

另外,我非常喜欢 Emacs 的一点是其详尽的文档。Emacs 的文档与 Neovim 的帮助页面完全不在一个量级。在 Emacs 中,你可以轻松查到某个快捷键的功能,或者触发某个命令需要按什么键。你可以通过关键词轻松搜索命令。这太棒了。在原生 Emacs 中,你甚至可以按 C-h m,它会打开当前场景下所有可用操作的列表(对于熟悉 Emacs 的人来说,我所说的“场景”是指主模式 Major Mode)。

With Doom Emacs, C-h m becomes less useful since all actions are shadowed by the Doom keybinds, but that is completely fine since most commands start with space anyway, and when you press space and wait a second it opens this convenient little popup that shows you all possible ways of continuing this keyboard combination. It feels like searching through a menu rather than memorizing keybinds. With time you naturally get faster at executing the different keybinds you use often and this becomes second nature, but for newcomers like me this is a very convenient feature. To be frank, there were plugins in Neovim that did this as well. But that is kind of the point: you had to know how to install plugins before you could get access to these kinds of features. And even then - as I said above - I did not find the Neovim help pages.

在 Doom Emacs 中,C-h m 的作用有所减弱,因为所有操作都被 Doom 的快捷键覆盖了,但这完全没问题,因为大多数命令都是以空格键开始的。当你按下空格键并等待一秒钟,它会弹出一个方便的小窗口,显示所有可能的后续按键组合。这感觉就像是在浏览菜单,而不是死记硬背快捷键。随着时间的推移,你会自然而然地熟练掌握常用的快捷键,并将其变成肌肉记忆,但对于像我这样的新手来说,这是一个非常方便的功能。坦白说,Neovim 中也有实现类似功能的插件。但问题的关键在于:你必须先知道如何安装插件才能获得这些功能。即便如此——正如我上面所说——我依然觉得 Neovim 的帮助页面不如 Emacs。