爱 Vim 的七个理由
编辑器 vi vim
![](/data/attachment/album/201608/29/154210iyeioo2oigoiysyz.png)


当我刚刚开始用 vi 文本编辑器的时候，我憎恨它！我认为这是有史以来设计上最痛苦和反人类的编辑器。但我还是决定我必须学会它，因为如果你使用的是 Unix，vi 无处不在并且是唯一一个保证你可以使用的编辑器。在 1998 年是如此，但是直到今天 vi 也仍然是可用的，现有的几乎每个发行版中，vi 基本上都是基础安装的一部分。


在我学会能使用任何功能前，我已经在 vi 上花费差不多 1 个月的时间，但是我仍然不喜欢它。不过那时我已经意识到有个强大的编辑器隐藏在这个古怪的外表后面。所以我坚持使用它，并且最终发现一旦你知道你在干什么，它就是一个快的令人难以置信的编辑器。


“vi” 这个名称是 “<ruby> 可视 <rp>  （ </rp> <rt>  visual </rt> <rp>  ） </rp></ruby>” 的缩写。在 vi 出现的时候，行编辑器是很普遍的，能一次性显示并编辑多个行是非同寻常的。Vim，来自“Vi IMproved”的缩写，最初由 Bram Moolenaar 发布于 1991 年，它成为了主要的仿 vi 软件，并且扩展了这个强大的编辑器已有的功能。Vim 强大的正则表达式和“:”命令行语法开始于行编辑和电传打字机时代。


Vim，有 40 年的历史了，有足够的时间发展出海量而复杂的技巧，即使是懂得最多的用户都不能完全掌握它。这里列出了一些爱 Vim 的理由：


1. 配色方案：你可能知道 Vim 有彩色语法高亮。但你知道可以下载数以百计的配色方案么？[在这找到些更好的](http://www.gilesorr.com/blog/vim-colours.html)。
2. 你再也不需要让你的手离开键盘或者去碰触鼠标。
3. Vi 或者 Vim 存在任何地方，甚至在 [OpenWRT](https://www.openwrt.org/) 里面也有 vi（好吧，其实是在 [BusyBox](https://busybox.net/)中，它挺好用的）。
4. Vimscript：你可能会想重映射几个键，但是你知道 Vim 有自己的编程语言么？你可以重新定义你的编辑器的行为，或者创造特定语言的编辑器扩展。（最近我在定制 Vim 用于 Ansible 的行为。）学习这个语言最佳的切入点是看 Steve Losh 著名的书《[Learn Vimscript the Hard Way](http://learnvimscriptthehardway.stevelosh.com/)》。
5. Vim 有插件。使用 [vundle](https://github.com/VundleVim/Vundle.vim)（我用的就是它）或者 [Pathogen](https://github.com/tpope/vim-pathogen) 来管理你的插件来提升 Vim 的功能。
6. 插件可以将 git（或者你选择的 VCS）集成到 Vim 中。
7. 有庞大而活跃的线上社区，如果你在线上提问关于 Vim 的问题，肯定会有人回答。


我一开始讨厌 vi 的可笑之处在于，这 5 年来不断的在尝试新的编辑器中碰壁，总是想找到“一些更好的”。我从来没有像讨厌 vi 一样讨厌过其它的编辑器，现在我已经使用它 17 年了，因为我想象不出一个更好的编辑器。额，或许有稍微好一点的：可以尝试下 Neovim -这是未来的主流。看起来 Bram Moolenaar 将会把 Neovim 的大部分融入到 Vim 第 8 版中，这意味着将会在现有的代码基础上减少 30%、更好的代码补全功能、真正的异步、内置终端、内置鼠标支持、完全兼容。


*在本文作者在多伦多的 [LinuxCon 演讲](http://sched.co/7JWz)中（LCTT 译注：LinuxCon 是 Linux 基金会举办的年度会议），他解释了一些在你可能错过的、过去四十年增加的杂乱的扩展和改进。这个内容不适合初学者，所以如果你不知道为什么“hjklia:wq”是很重要的，这就可能不是讲给你听的。它还会涉及一点关于 vi 的历史，因为知道一些历史能帮助我们理解我们的处境。关注他的演讲能让你知道如何使你最喜欢的编辑器更好更快。*




---


via: <https://opensource.com/business/16/8/7-reasons-love-vim>


作者：[Giles Orr](https://opensource.com/users/gilesorr) 译者：[hkurj](https://github.com/hkurj) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
When I started using the vi text editor, I hated it. I thought it was the most painful and counter-intuitive editor ever designed. But I'd decided I had to learn the thing, because if you're using Unix, vi was everywhere and was the only editor you were guaranteed to have access to. That was back in 1998, but it remains true today—vi is available, usually as part of the base install, on almost every Linux distribution in existence.

It took about a month before I could do anything with any proficiency in vi and I still didn't love it, but by then I'd realized that there was an insanely powerful editor hiding behind this bizarre facade. So I stuck with it, and eventually found out that once you know what you're doing, it's an incredibly fast editor.

The name "vi" is short for "visual." When vi originated, line editing was the norm and being able to display and edit multiple lines at once was unusual. Vim, a contraction of "Vi IMproved" and originally released by Bram Moolenaar in 1991, has become the dominant vi clone and continued to extend the capabilities of an already powerful editor. Vim's powerful regex and ":" command-line syntax started in the world of line editing and teletypes.

Vim, with its 40 years of history, has had time to develop a massive and complex bag of tricks that even the most knowledgeable users don't fully grasp. Here are a few reasons to love Vim:

- Colour schemes: You probably know Vim has colour syntax highlighting. Did you know you can download literally hundreds of colour schemes?
[Find some of the better ones here](http://www.gilesorr.com/blog/vim-colours.html). - You never need to take your hands off the keyboard or reach for the mouse.
- Vi or Vim is everywhere. Even
[OpenWRT](https://www.openwrt.org/)has vi (okay, it's[BusyBox](https://busybox.net/), but it works). - Vimscript: You've probably remapped a few keys, but did you know that Vim has its own programming language? You can rewrite the behaviour of your editor, or create language-specific editor extensions. (Recently I've spent time customizing Vim's behaviour with Ansible.) The best entry point to the language is Steve Losh's brilliant
.[Learn Vimscript the Hard Way](http://learnvimscriptthehardway.stevelosh.com/) - Vim has plugins. Use
[Vundle](https://github.com/VundleVim/Vundle.vim)(my choice) or[Pathogen](https://github.com/tpope/vim-pathogen)to manage your plugins to improve Vim's capabilities. - Plugins to integrate git (or your VCS of choice) into Vim are available.
- The online community is huge and active, and if you ask your question about Vim online, it will be answered.

The irony of my original hatred of vi is that I'd been bouncing from editor to editor for five years, always looking for "something better." I never hated any editor as much as I hated vi, and now I've stuck with it for 17 years because I can no longer imagine a better editor. Well, maybe a little better: Go try [Neovim](https://neovim.io/)—it's the future. It looks like Bram Moolenaar will be merging most of Neovim into Vim version 8, which will mean a 30% reduction in the code base, better tab completion, real async, built-in terminal, built-in mouse support, and complete compatibility.

*In his LinuxCon talk in Toronto, Giles will explain some of the features you may have missed in the welter of extensions and improvements added in the past four decades. The class isn't for beginners, so if you don't know why "hjklia:wq" are important, this probably isn't the talk for you. He'll also cover a bit about the history of vi, because knowing some history helps to understand how we've ended up where we are now. Attend his talk to find out how to make your favourite editor better and faster.*

## 13 Comments