EMACS-DOCUMENT

=============>随便,谢谢

Making Emacs work like my Neovim setup

My configuration repositories

*我的配置资料库

属性: :CUSTOM_ID: my-configuration-repositories :CUSTOM_ID my-configuration-repositories

结束:

Do not expect extremely polished dotfiles. I know some of you will be pulling your hair out with some of the stuff you see here: 不要期待非常完善的网络文件。我知道你们中的一些人会因为这里看到的一些东西而抓狂:

I will not give you counsel, saying do this, or do that. For not in doing or contriving, nor in choosing between this course and another, can I avail; but only in knowing what was and is, and in part also what shall be. 我不给你出什么主意,说什么,做什么。因为我既不去做,也不去想,既不去选择,也不去选择。而只是在知道过去和现在是什么样子,并且部分地知道将来会是什么样子。

--- Galadriel 推荐- - - - - -凯兰崔尔

I've been a Neovim user and fan for a bit more than a year now. After having given it a reasonable spin I've become quite efficient at working with it, and it's been a pleasure all the way through. Certainly, I'm a lot faster with my Tmux/Neovim/gitsh workspace than I was with either Atom, Sublime Text or VSCode, and I feel a lot more comfortable. 我成为Neovim的用户和粉丝已经有一年多了。在给它一个合理的解释后,我已经变得相当有效率地与它一起工作,而且它一直是一种乐趣。当然,使用Tmux/Neovim/gitsh工作空间比使用Atom、Sublime Text或VSCode要快得多,而且我感觉舒服多了。

From this point and forward, and although I use Neovim, I'll be using the words Vim and Neovim interchangeably. Whether I refer to the software packages or to a specific user community should be clear in context. 从现在开始,尽管我使用Neovim,但我将交替使用Vim和Neovim这两个词。无论我指的是软件包还是特定的用户社区,在上下文中都应该是清楚的。

During the last weeks I've noticed several tools and concepts in the Emacs which I've found attractive enough to try out the platform. These include: 在过去的几周里,我注意到Emacs中有几个工具和概念,我觉得它们很有吸引力,可以试用这个平台。这些包括:

  • Org-mode: I've tried the Vim port and although it's a wonderful effort at emulating the original Emacs package, I think it would require quite a bit of an investment to reach the current scope of Org-mode. I plan to use Org-mode for GTD and for generic notetaking; also being able to write my Emacs configuration in Org-mode is a beauty.
  • Org-mode:我已经尝试了Vim端口,虽然它是一个很好的努力,以模仿原来的Emacs包,我认为它将需要相当多的投资,以达到目前的范围的组织模式。我计划使用组织模式的GTD和一般的笔记;而且,能够在组织模式下编写Emacs配置也是一件美妙的事情。
  • Magit: with my Tmux setup, I initialize several workspaces for each project with a script, and my standard workspace includes a Vim window, and another window with several panes. One of these is always a gitsh instance. It's worked wonderfully for me but after having tried the Magit interface there's no question that I'm going to be needing less keystrokes to do my thing, all while enjoying a beautiful interface.
  • Magit:在我的Tmux设置中,我用一个脚本为每个项目初始化了几个工作空间,我的标准工作空间包括一个Vim窗口,另一个窗口有几个窗格。其中一个总是gitsh实例。它对我来说工作得很好,但在尝试了Magit界面后,毫无疑问,我将需要更少的按键来做我的事情,同时享受一个美丽的界面。
  • Lisp: admittedly, I could do with Vim but Emacs has a Lisp interpreter at its core, and integration is granted. I don't use Lisp at work and I'm a beginner, but it feels like it's impossible to find anything about Lisp support in Vim where the Emacs solutions are not mentioned.
  • Lisp:无可否认,我可以用Vim,但Emacs的核心是一个Lisp解释器,集成是被允许的。我在工作中不使用Lisp,而且我是一个初学者,但是在没有提到Emacs解决方案的Vim中,似乎不可能找到任何有关Lisp支持的内容。
  • Integration: I like the never leave your editor and kitchen sink in Emacs approach and although I doubt I'll ever manage emails or browse the web inside Emacs, I feel all warm and fuzzy when I realize I could if I wanted to. Many of these things are arguably possible in Vim but it feels like the Emacs community leans more towards it than the Vim counterpart.

-整合:我喜欢Emacs中的“永远不要离开你的编辑器和厨房水槽”的方法,虽然我怀疑我是否能在Emacs中管理电子邮件或浏览网页,但当我意识到我可以这么做时,我感到温暖和模糊。这些事情在Vim中都是可能的,但是Emacs社区似乎比Vim社区更倾向于此。

So I decided to surrender to my sacrilegous self and try to emulate everything I do with Vim from an empty Emacs config file built with Org-mode. And I must say: it's been a breeze! I haven't even needed to dedicate much time to learning actual Emacs, and what I've learned has actually been nice. In this post I'll try to go through what I did to rebuild my setup; I hope you'll enjoy it as much as I did. 因此,我决定向我的圣物自我投降,并试图从一个用Org-mode构建的空Emacs配置文件中模仿我使用Vim*所做的一切。我得说:这简直是小菜一碟!我甚至不需要花太多时间来学习实际的Emacs,而我所学到的实际上是很好的。在这篇文章中,我将尝试通过我做了什么来重建我的设置;我希望你会和我一样喜欢它。

Package management

*包管理

属性: :CUSTOM_ID: package-management :CUSTOM_ID:包管理

结束:

For package management needs the Vim community has contributed several awesome packages like Pathogen or vim-plug among the many worth mentioning. I've always used vim-plug and never found a problem with it. As active as the Emacs community is in regards to package development, I expected a solution that would provide the same level of comfort. 对于包管理需求,Vim社区已经提供了几个非常棒的包,比如病原体vim-plug等。我一直使用vimm -plug,从来没有发现它有什么问题。尽管Emacs社区在包开发方面非常活跃,但我希望有一个能够提供相同舒适度的解决方案。

Emacs comes bundled with Package, and this is as much as I'm aware of: it takes care of package repository management, and to configure it I only needed to add the links to those repositories and initialize it. Emacs与包绑定在一起,这是我所知道的:它负责包存储库管理,为了配置它,我只需要向这些存储库添加链接并初始化它。

Package, however, does not take responsibility for automatic fetching, updates, and encapsulation of configuration (which vim-plug does, and very well). For this, I've found the de-facto solution to be use-package. To be able to work with use-package using its minimal functionality, this is all you need to know: 但是,Package并不负责配置的自动获取、更新和封装(而vim-plug可以很好地完成这些工作)。对于这个问题,我发现实际上的解决方案是use-package。为了能够使用use-package的最小功能,这是你需要知道的:

  • use-package can fetch whatever packages are made available through your Package configuration.
  • use-package可以通过包配置获取任何可用的包。
  • A basic declaration looks like this: (use-package package-name).

-基本声明如下:=(use-package package-name)=。

  • If you add :ensure t, you'll get automatic fetching of your package and startup checks: (use-package package-name :ensure t).

-如果你添加=:ensure t=,你会得到你的包和启动检查:=(use-package package-name:ensure t)=。

  • If you add :defer t, your package will load lazily: (use-package package-name :ensure t :defer t).

-如果您添加=:defer t=,您的包将延迟加载:=(use-package package-name:ensure t:defer t)=。

  • You can add :init, and everything you pass it will be evaluated before the package loads. Here's where you'll use (setq key 'value), for example.

-您可以添加=:init=,您传递给它的所有内容都将在包加载之前进行评估。例如,这里将使用=(setq key 'value)=。

  • You can add :config, and everything you pass it will be evaluated after the package loads. Here's where you'll initialize modes, for example.

-你可以添加=:config=,你传递给它的一切将在包加载后被评估。例如,这里是初始化模式的地方。

It didn't take me too long to learn this, and use-package allegedly does a thousand more things which I'll begin to learn with time. 我很快就学会了这个,use-package据说可以做上千件事情,随着时间的推移,我将开始学习这些事情。

Vim things and Evil things

*充满活力的事物和邪恶的事物

属性: :CUSTOM_ID: vim-things-and-evil-things :CUSTOM_ID vim-things-and-evil-things

结束:

Evil calls itself the extensible vi layer for Emacs, and claims that it emulates the main features of Vim. I'd say this is an understatement; Evil feels like a complete re-implementation of Vim's porcelain. It makes you feel right at home once you start using it: Evil自称是Emacs的可扩展vi层,并声称它模仿了Vim的主要特性。我认为这是一种保守的说法;《邪恶》感觉就像Vim的瓷器的完全重新实现。一旦你开始使用它,它会让你感觉就像在家里一样:

  • Macros: these work exactly as expected. Even making a visual selection and running :norm @q runs your q macro on the visual selection, just like in Vim. The only difference I've noticed is that execution is minimally slower, but the decrease in speed does not compare to that of VSCode's implementation of Vim macros, for example.

-宏:这些工作完全符合预期。甚至在可视选择中运行=:norm @q=宏,就像在Vim中一样。我注意到的惟一区别是执行速度有最低限度的降低,但是速度的降低与VSCode实现Vim宏的速度相比并没有什么不同。

  • Registers: registers also work exactly as expected. The only problem I've had is that I can't copy to the clipboard by using the + register, but this must be a misconfiguration on my part for Emac's clipboard integration, so I suspect it won't be a huge effort to fix it.

-寄存器:寄存器的工作也完全符合预期。我遇到的唯一问题是,我不能使用=+=寄存器复制到剪贴板,但这一定是我对Emac的剪贴板集成的一个错误配置,所以我怀疑修复它并不需要很大的努力。

-命令重复(.):工作正常,除了一些由其他包引入的操作。不幸的是,其中之一是evil-surroundhttps://github.com/emacs-evil/evil- d/issues/133

  • Auto-save and safety/backup features: they can be easily configured to not happen at all or to happen in a specified directory (I'm using /tmp).

-自动保存和安全/备份功能:它们可以很容易地配置为根本不发生或发生在指定的目录(我使用=/tmp=)。

  • Ex commands (those starting with a colon :) like substitution, substitution with manual confirmation, invocation of macros in normal mode, etc. All work great and I haven't found an instance where they don't.
  • Ex命令(那些以冒号=:=开头的命令),如替换、手动确认的替换、正常模式下宏的调用等。所有的工作都很好,我还没有发现一个不这样的例子。
  • Marks: I don't make extensive use of them, but they also seem to be working great.
  • Marks:我没有充分利用它们,但它们似乎也很有效。

Using evil-leader you can configure a leader key. I've configured mine to Space, and added a several keybindings. The same results can be achieved with the more powerful general.el, and if you need chained keystrokes to produce a command (for example, I used to have <leader> wq, which I found faster than :wq), you can use Hydra. I haven't found a need for these and I'm doing just fine with evil-leader. 使用evil-leader您可以配置一个leader密钥。我已经将我的配置为=Space=,并添加了几个键绑定。可以实现相同的结果与更强大的[[https://github.com/noctuid/general.el] [general.el]],如果你需要链接按键产生一个命令(例如,我曾经有过= <领袖> wq ,我发现速度比:wq =),您可以使用[[https://github.com/abo-abo/hydra] [Hydra]]。我还没有发现需要这些,我做得很好,与邪恶领袖。

Project management and file navigation

*项目管理和文件导航

属性: :CUSTOM_ID: project-management-and-file-navigation :CUSTOM_ID project-management-and-file-navigation

结束:

My setup using Vim is basically fzf (which I use for many more things outside Vim) powered by Ag (or The Silver Searcher) for finding files and ripgrep for finding text in a project. This works flawlessly. 我的设置使用Vim基本上是[[https://github.com/junegunn/fzf] [fzf]](我使用Vim以外的很多东西)由[[https://github.com/ggreer/the_silver_searcher] [Ag(或银搜索者)]]寻找文件和[[https://github.com/BurntSushi/ripgrep] [ripgrep]]寻找文本在一个项目中。这很完美。

I've found the combination of Helm and Projectile to be an adequate substitute to my former setup. On big projects like Servo, the difference in speed is noticeable (in favor of the Vim configuration) but I can live with that. I don't know why, but there's a longer load time on the Emacs setup. 我发现Helm射弹的组合是我以前设置的一个足够的替代品。在像Servo这样的大项目中,速度上的差异是显而易见的(有利于Vim配置),但是我可以接受。我不知道为什么,但是Emacs设置的加载时间更长。

The scope of fzf is by no means comparable to that of Helm and Projectile, so this is not meant to be a comparison but it does happen to be what covers my file-finding needs. Both setups enable extremely quick fuzzy search for files and content. fzf的范围绝不能与Helm和射弹相比,所以这并不是一个比较,但它正好满足了我的文件查找需求。这两种设置都支持对文件和内容进行极其快速的模糊搜索。

As you can see on my Emacs configuration, my setup for Helm and Projectile is extremely basic and I haven't needed further customization yet. And I must say: they look much prettier than the Vim setup I use. 你可以看到关于我的Emacs配置,我的Helm和的设置非常简单,我还不需要进一步的定制。而且我必须说:它们看起来比我使用的Vim设置漂亮得多。

Specific packages

*具体包

属性: :CUSTOM_ID: specific-packages :CUSTOM_ID:特定的包

结束:

A quick search on your favorite engine will yield at least a couple different solutions to problems some of the nicest Vim plugins solve. Here's a quick list to encourage you: 在你最喜欢的引擎上快速搜索一下,你会发现至少有两个不同的解决方案可以解决一些Vim插件所解决的问题。这里有一个快速的列表来鼓励你:

  • VimCompletesMe: I enjoyed the simplicity of VimCompletesMe, which basically only extends Vim's autocomplete features and lets you use them by pressing Tab. I found that the Emacs package auto-complete provides the same ease of use and also feels lightweight.
  • VimCompletesMe:我很喜欢VimCompletesMe的简单性,它基本上只是扩展了Vim的自动完成功能,并让你使用他们按=Tab=。我发现Emacs包auto-complete提供了同样的易用性,而且感觉很轻量。
  • vim-tmux-navigator: in Tmux, I use <my-tmux-prefix>-[hjkl] to navigate panes. Using Vim, I wanted windows to behave as if they were on the same level as Tmux panes, and vim-tmux-navigator works great for that. For Emacs there's a port called emacs-tmux-navigator.

-vim-tmux-navigator:在Tmux中,我使用=<my-tmux-prefix>-[hjkl]=浏览窗格。使用Vim,我希望windows的行为就像它们与Tmux窗格处于同一层,而Vim - Tmux -navigator在这方面非常有效。对于Emacs,有一个名为Emacs -tmux-navigator的端口。

  • auto-pairs: Emacs has a built-in mode that suits my needs. Enable it with (electric-pair-mode 1).
  • auto-pair: Emacs有一个适合我需要的内置模式。使用=(电子对模式1)=启用它。
  • NerdTree: the Emacs port NeoTree does the original justice and, although I haven't gotten there yet, it can also be extended with Git integration and icons if you use GUI Emacs.
  • NerdTree: Emacs端口NeoTree实现了最初的功能,虽然我还没有实现,但是如果您使用GUI Emacs,也可以使用Git集成和图标对其进行扩展。
  • vim-emoji-complete: I use this to navigate and autocomplete through a list of Unicode emojis. In the company I work at, we use Gitmojis extensively, so this is actually an important part of my workflow. You should check them out too, it may seem silly but it's quite helpful to be able to recognize what every commit does without even reading the message. For Emacs, there's an even better solution for inserting emojis into your buffer: emojify. This thing even lets you customize the list of emojis you get. For example, I've chosen to only display Unicode emojis, and not GitHub or vanilla ASCII emojis.
  • vim-emoji-complete:我使用这个来导航和自动完成Unicode表情符号列表。在我工作的公司,我们使用[[https://gitmoji.carloscuesta。[Gitmojis]]非常广泛,所以这实际上是我工作流程中的一个重要部分。您也应该检查它们,这可能看起来很傻,但是能够在不阅读消息的情况下识别每个提交所做的事情是很有帮助的。对于Emacs,有一个更好的解决方案可以将emojis插入到您的缓冲区中:emojify。这个东西甚至可以让你定制你得到的表情符号列表。例如,我选择只显示Unicode表情符号,而不显示GitHub或普通的ASCII表情符号。

Regarding Tim Pope plugins: there's an Emacs port for everything Mr. Pope does. Many of these go on top of Evil, and it's a no-brainer to add them and use them if you're used to their Vim counterpart. 关于[[https://github.com/tpope?[Tim Pope插件]]:这里有一个Emacs端口,可以支持Pope先生所做的任何事情。它们中的许多都是在Evil之上的,如果您已经习惯了Vim版本,那么添加它们并使用它们是非常简单的。

Theming

*主题

属性: :CUSTOM_ID: theming :CUSTOM_ID:主题

结束:

Themes are really easy to set up on Emacs. Just add a use-package declaration and then load it with (load-theme 'pretty-theme t). The second argument automatically answers “yes” to a couple security questions that pop up every time you load a new theme. Emacs themes can run arbitrary Elisp so they can do a lot of nasty stuff. Make sure you trust the sources where you get your themes. 在Emacs上设置主题非常容易。只需添加一个use-package声明,然后用=(load-theme 'pretty-theme t)=加载它。第二个参数会自动回答“是”,每次加载新主题时都会弹出几个安全问题。Emacs主题可以运行任意的Elisp,因此它们可以做很多令人讨厌的事情。确保你相信你获得主题的来源。

If I had to complain about anything, I'd say most themes work much better on the GUI version of Emacs, and I use the terminal version (emacs -nw). Many themes' backgrounds are broken and show up differently depending on your $TERM environment variable. Of the ones I've tried, I've found Monokai and Badger to work look best on terminal Emacs. 如果我不得不抱怨什么的话,我会说大多数主题在Emacs的GUI版本上工作得更好,我使用的是终端版本(= Emacs -nw=)。许多主题的背景都是破碎的,并且根据您的=$TERM= environment变量的不同而呈现出不同的效果。在我尝试过的版本中,我发现MonokaiBadger在终端Emacs上效果最好。

Performance and server mode

*性能和服务器模式

属性: :CUSTOM_ID: performance-and-server-mode :CUSTOM_ID performance-and-server-mode

结束:

Neovim feels a lot snappier for a lot of interactions. This, however, is not important at all most of the time, because it never shows while writing or navigating text inside a buffer. Neovim给人的感觉是有很多互动的。但是,在大多数情况下,这一点都不重要,因为在缓冲区中写入或导航文本时,它不会显示出来。

The main difference in performance shows in startup time. Here's a quick-and-dirty comparison using time, with my full configuration loaded on both programs: 主要的性能差异表现在启动时间上。这里是一个快速和肮脏的比较使用=时间=,我的全部配置加载在两个程序:

➜ time nvim +q
nvim +q 0.13s user 0.02s system 97% cpu 0.160 total
➜ time em +q
emacs -nw +q 2.14s user 0.12s system 44% cpu 5.121 total

Please do not evaluate this as any kind of benchmark: I haven't done anything to improve startup time on either Neovim or Emacs (like using use-package's :defer t). 请不要将此评估为任何一种基准:我没有做任何事情来提高Neovim或Emacs上的启动时间(比如使用use-package的=:defer t=)。

The two seconds of waiting is OK if you open Emacs once and work from there for each project. It is not OK if you're using Emacs as a default editor for stuff like Git, or even your $EDITOR environment variable. 如果您打开Emacs一次,然后从那里开始为每个项目工作,那么两秒钟的等待是可以的。如果您使用Emacs作为Git之类的默认编辑器,甚至您的=$ editor =环境变量,都是不合适的。

Emac's solution to this is server mode. Basically, you start an Emacs server on your fully loaded instance (the one that took two seconds to open). From then on, if you want to open Emacs for a quick edit and you don't need the default directory to be the one you called Emacs on, you can go emacsclient. Emac的解决方案是“服务器模式”。基本上,您可以在完全加载的实例上启动Emacs服务器(打开这个实例需要两秒钟)。从那时起,如果您希望打开Emacs进行快速编辑,并且不需要在缺省目录下调用Emacs,那么可以使用=emacsclient=。

➜ time emacsclient -nw -c -a "" +q
emacsclient -nw -c -a "" +q 0.00s user 0.00s system 0% cpu 3.010 total

Yep - instant! That's more like it. I have that gravely arcane command (emacsclient -nw -c -a "") set as my $EDITOR environment variable. Also, I have two aliases: 是的- 即时 !这才像话。我把那个晦涩难懂的命令(emacsclient -nw -c -a "")设置为我的=$EDITOR=环境变量。此外,我有两个别名:

  • em opens a full Emacs instance.
  • =em=打开一个完整的Emacs实例。
  • e is used to manually call emacsclient -nw -c -a "", which is also my $EDITOR.
  • =e=是用来手动调用=emacsclient -nw -c -a ""=,这也是我的=$EDITOR=。

This is admittedly a lot of work compared to just having an editor that loads quickly all the time. But it works! You can see the section of my config file where I set up server mode (basically, there's no setup). 不可否认,与总是快速加载的编辑器相比,这是一项工作量很大的工作。但它工作!您可以看到我的配置文件中设置服务器模式的部分(基本上没有设置)。

Conclusion

*结论

属性: :CUSTOM_ID: conclusion 结论:CUSTOM_ID:

结束:

Voilà! Now I can continue Vimming around. I can Vim around while writing Lisp comfortably, doing some GTD in Org-mode, using Magit, and having leveled up in snobbism 😭. null

Jokes aside, it feels good to have given both editors a chance. I have certainly had a taste of why both communities are so passionate about their preferences. I'll make another post as soon as I've discovered if I can actually use my new setup as fluently as my former configuration. Until then, happy new year! 撇开笑话不谈,给两位编辑一个机会感觉很好。我当然已经体会到了为什么这两个社区对他们的偏好如此热情。一旦我发现我可以像以前的配置一样流畅地使用我的新设置,我就会写另一篇文章。在那之前,新年快乐!