多语言编程必备的十大 Vim 插件
Vim 插件

> 
> 使用这 10 个 Vim 插件，可以让你在写代码或运维时，感觉更棒。
> 
> 
> 


![](/data/attachment/album/201912/05/062256bnauidfsf7155d1n.jpeg)


我使用 [Vim](https://www.vim.org/) 文本编辑器大约 20 年了。有一段时间，我一直在定制我的 Vim 配置，但在只有在最近两年我才会使用插件。


最近，当我重新安装系统时（就像我经常做的那样），我觉得这是一次好的机会，我想找出多种编程语言环境下的最佳 Vim 插件，以及如何将这些插件和每种语言结合起来。


有时，我会为特定的语言和配置使用特定的插件（例如，我只在 Ansible 配置中安装 Rocannon），在此不细讲了。不过下面介绍的 10 个 Vim 插件都是我的最爱，无论使用哪种编程语言，我几乎都会使用它们。


### 1、Volt


我的首选并不是一个插件，但是它可以替换类似于 [Vundle](https://github.com/VundleVim/Vundle.vim) 的插件，所以在此介绍。


[Volt](https://github.com/vim-volt/volt) 是一个不依存于 Vim 的 Vim 插件管理器。你可以用它安装插件，并创建名为“profile”的插件组合。你可以使用一个简单的命令 `volt profile set myprofile` 启用新的配置。这样我可以做到这样的事情，如为 Python 配置单独启用 [indentpython](https://github.com/vim-scripts/indentpython.vim) 插件。Volt 还提供了一种针对每个插件配置的简单方法，这些配置会在“profile”之间共享，因此只需要安装一次插件，就可以在多个“profile”之间使用。


Volt 还是相对较新且不够完美（比如，不管你想要使用多少个“profile”，每个插件只能有一个配置文件），但除此之外，我发现它非常方便、快速和简单。


![Volt plugin](/data/attachment/album/201912/05/062340rz2hfhu5uullblbl.gif "Volt plugin")


### 2、Vim-Rainbow


除了 Python，几乎所有的主流编程语言都使用括号（小括号、方括号和大括号）。通常，它们会嵌套使用多对括号，因此很难搞清楚某个括号的开闭区间。我发现自己经常要数小括号，尤其是在复杂的 Bash 脚本中，以确保无误。


这时候就需要 [vim-rainbow](http://github.com/frazrepo/vim-rainbow) 插件！它为每对括号设置不同的颜色，因此很容易识别出哪些括号是一对括号。它非常有用而且五彩斑斓。


![vim-rainbow plugin](/data/attachment/album/201912/05/062341ima6c9a1w2acwuyz.png "vim-rainbow plugin")


### 3、lightline


Vim 有很多这种插件，例如 [Powerline](https://github.com/powerline/powerline)，它会在底部栏显示你正在处理的文件、光标所在的文件位置以及文件类型等信息。这些插件各有利弊，在简单比较后，我选择了 [lightline](http://github.com/itchyny/lightline.vim)。它相对较小，便于安装和扩展，并且不依赖于其他工具或插件。


![Lightline plugin](/data/attachment/album/201912/05/062341zbqwr88dvfq6sd8s.png "Lightline plugin")


### 4、NERDTree


[NERDTree](http://github.com/scrooloose/nerdtree) 是一个很经典的插件。在大型项目中，你可能很难找到想要编辑的内容所在文件的确切名称和路径。使用快捷键（我使用的是 `F7`，因为我在 `.vimrc` 中配置了这个快捷键），搜索窗会以垂直分屏的方式打开，就可以轻松找到所需文件并打开它。对于大型项目，这是必备插件。对于那些经常忘记文件名的人也很有用，比如我。


![NERDTree vim plugin](/data/attachment/album/201912/05/062342w464yfz4z9f9h99y.gif "NERDTree vim plugin")


### 5、NERD Commenter


程序员们在写代码时，有时会遇到一些难以调试的问题，导致他们想要注释或不执行某段代码。这时候就需要 [NERD Commenter](http://github.com/scrooloose/nerdcommenter) 出场了。选择代码段，按 `Leader 键 + cc`，代码就会被注释掉。（标准的 Vim Leader 键 是 `/` 字符。）按 `Leader 键 + cn`，取消注释。对于大多数文件类型，NERD Commenter 会自动使用正确的注释符。例如，如果你正在编辑 [BIND 区域文件](https://en.wikipedia.org/wiki/Zone_file#File_format)，并将文件类型设置为 BIND 区域文件，Vim 会正确地使用 `;`（分号）字符进行注释。


![NERD Commenter](/data/attachment/album/201912/05/062343mcopxuiwjimmoip3.gif "NERD Commenter")


### 6、Solarized


我喜欢我的 Vim 主题配色。我也喜欢终端的主题色。我一直在 Vim 上使用 [Solarized](https://github.com/altercation/vim-colors-solarized) 配色，并且将我的终端、文件夹配色和 Vim 设为一致。


但是，有时我会根据周边环境、屏幕亮度以及是否需要分享投屏，来切换明暗模式。


显然，你可以选择自己喜欢的任何配色方案，但我喜欢 `Solarized`，因为它有明暗模式功能，它可以简单快捷地切换两种模式。我的第二个选择是 [Monokai](https://github.com/sickill/vim-monokai)。Volt 插件管理器让我可以轻松地在两者之间切换，因此我在 Python 编程时，使用 Monokai；Bash 编程时，使用 Solarized。


我没有给 Solarized 找相应的图片，因为本文中的所有其他图片都使用了 Solarized 中的浅色或深色效果，可以确认一下这些图片。


### 7、fzf


当寻找一个文件时，有时你想要一个文件浏览器，有时你只想在键盘上敲打出与文件名模糊匹配的内容，对吗？


[fzf](https://github.com/junegunn/fzf.vim)（全称 “模糊查找器”）插件提供了这一功能。打出 `:FZF` 并输入文件名内容。不断缩短的列表将显示出与你输入的文件名内容相匹配的一些文件。我经常使用它，最近使用它的频率估计比使用 NERDTree 还多。缺点是这个插件依赖于 `fzf binary`，因此也必须安装这个依赖包。它适用于 Fedora、Debian 和 Arch，据我所知并不在 EPEL 中。


![fzf Vim plugin](/data/attachment/album/201912/05/062343biuiilog4fwicqw7.gif "fzf Vim plugin")


### 8、ack


有时，你需要搜索包含特定行或特定单词的文件。我真的很喜欢使用 [ack](https://github.com/mileszs/ack.vim) 插件，最好与 `ag` 结合使用，它俩的组合又被称为 “[silver searcher](https://github.com/ggreer/the_silver_searcher)”。这一组合的速度非常快，覆盖了 `grep` 或 `vimgrep` 的绝大多数使用场景。缺点是你需要安装 `ack` 或 `ag` 才能正常运行。好消息是 Fedora 和 EPEL7 都可以使用 `ag` 和 `ack`。


![ack vim plugin](/data/attachment/album/201912/05/062344puy0y3xgtxiarjdb.gif "ack vim plugin")


### 9、gitgutter


大多数 IT 人员都使用 [Git](https://opensource.com/resources/what-is-git) 和 Git 仓库中的文件进行工作。[gitgutter](https://github.com/airblade/vim-gitgutter) 插件在行号附近添加了一列，通过符号显示该行的状态为：已更改（`~`）、已添加（`+`）或者已删除（`-`）。这有利于跟踪你所做的更改，并且可以使你专注于手头的任务，例如编写补丁来修复一个关键错误。


![gitgutter vim plugin](/data/attachment/album/201912/05/062344c0p1pkryufhr1fmz.png "gitgutter vim plugin")


### 10、Tag List


如果你在一个很大的文件中编写代码，会很容易忘记当前所在的位置，你可能需要上下滚动来查找某个功能。使用 [Tag List](https://github.com/vim-scripts/taglist.vim) 插件，只需要输入 `:Tlist`，就能垂直分屏显示出包含变量、类型、类和函数的代码，你可以轻松跳转到这些变量、类型、类和函数。这个功能对于多语言同样适用，例如 Java、Python 以及任何能够使用 `ctags` 功能的文件类型。


![Tag List vim plugin](/data/attachment/album/201912/05/062345d4fkme7550me7xji.gif "Tag List vim plugin) ) ) ")


以上介绍的 10 个 Vim 插件使我作为系统管理员和兼职程序员的生活变得更轻松。你正在使用哪些 Vim 插件？请在评论中分享你最爱的插件。




---


via: <https://opensource.com/article/19/11/vim-plugins>


作者：[Maxim Burgerhout](https://opensource.com/users/wzzrd) 选题：[lujun9972](https://github.com/lujun9972) 译者：[hello-wn](https://github.com/hello-wn) 校对：[wxy](https://github.com/wxy)


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


OK
I've been a user of the [Vim](https://www.vim.org/) text editor for about two decades. For a little while, I have been customizing my Vim configuration, only using plugins for the last couple of years.


Recently, when I was redoing my setup (as I do every so often), I decided it was a good opportunity to identify the best Vim plugins for programming in multiple languages and a way to combine those plugins for each language I program in.

I do use certain plugins for specific languages and profiles (e.g., I only install Rocannon in my Ansible profile), and I won't go into those here—that would be a *long* list. But the 10 Vim plugins described below are my favorites, the ones I use in virtually every profile I have, no matter what programming language I'm using.

## 1. Volt

My number one pick isn't even a plugin; rather, it replaces plugins like [Vundle](https://github.com/VundleVim/Vundle.vim), so I'm listing it here.

[Volt](https://github.com/vim-volt/volt) is a Vim plugin manager that lives outside Vim. You can use it to install plugins and create combinations of plugins called "profiles." You can enable a new profile with a single command: **volt profile set myprofile**. That way, I can do things like enable the [indentpython](https://github.com/vim-scripts/indentpython.vim) plugin for just my Python profile. Volt also offers a simple way to do per-plugin configurations. The configuration is shared between profiles, so you can install plugins once and use them in multiple profiles.

Volt is still relatively new and not perfect (e.g., you can have just one configuration file per plugin, no matter how many profiles you are using), but apart from that, I find it extremely handy, extremely fast, and extremely simple.

![Volt plugin Volt plugin](https://opensource.com/sites/default/files/uploads/vim-volt.gif)

## 2. Vim-Rainbow

Except for Python, virtually all major programming languages use brackets. Round ones, square ones, and curly ones. Often, they use multiple pairs of brackets, with one pair embedded in another. Figuring out which closing bracket belongs to what opening bracket can become difficult and annoying. I often find myself counting round brackets—especially in complicated Bash scripts—to make sure I got everything right.

Here's the [vim-rainbow](http://github.com/frazrepo/vim-rainbow) plugin to the rescue! It gives every pair of brackets a unique color, so it's easy to identify which brackets belong to each other. It's very useful and very colorful, too.

![vim-rainbow plugin vim-rainbow plugin](https://opensource.com/sites/default/files/uploads/vim-rainbox.png)

## 3. lightline

There are a lot of plugins for Vim, such as [Powerline](https://github.com/powerline/powerline), that put a bar at the bottom of the screen to show you what file you are working on, where you are in the file, what type of file it is, etc. Each of these plugins has advantages and disadvantages, and after briefly weighing them, I chose [lightline](http://github.com/itchyny/lightline.vim). It's relatively small, easy to set up, quite extensible if you are into that kind of thing, and doesn't require any other tooling or plugins.

![Lightline plugin Lightline plugin](https://opensource.com/sites/default/files/uploads/lightline.png)

## 4. NERDTree

[NERDTree](http://github.com/scrooloose/nerdtree) is a classic. In large projects, it can be hard to find the exact name and location of the one file that includes the one line you need to edit. With a quick keystroke (**F7**, in my case, as I bound NERDTree to F7 in my .vimrc configuration file), an explorer window opens in a vertical split, and I can easily browse to the file I want and open it. It's a must for large bodies of code. Or for people that tend to forget filenames, like me.

![NERDTree vim plugin NERDTree vim plugin](https://opensource.com/sites/default/files/uploads/nerdtree.gif)

## 5. NERD Commenter

All programmers, at some time, write code that introduces a hard-to-debug problem that leads them to decide to comment out or undo the code. This is where [NERD Commenter](http://github.com/scrooloose/nerdcommenter) comes in. Select the code, hit **Leader+cc**, and your code is commented. (The standard Vim Leader key is the **/** character.) Hit **Leader+cn, **and your code is uncommented. NERD Commenter should automatically use the right commenting character for most file types. For example, if you are editing a [BIND zone file](https://en.wikipedia.org/wiki/Zone_file#File_format) and set the file type to bind zone, Vim will correctly use the **;** (semicolon) character to comment lines out.

![NERD Commenter NERD Commenter](https://opensource.com/sites/default/files/uploads/nerdcommenter.gif)

## 6. Solarized

I love my Vim colors. Really, I love terminal colors in general. I've been using the [Solarized](https://github.com/altercation/vim-colors-solarized) color scheme for Vim for a long time, and I set up my terminal, dir_colors, and Vim to be consistent.

Every now and then, though, I toggle between light and dark modes, depending on what kind of environment I'm in, the amount of light falling on my screen, and whether I need to put something on a big screen for others to read.

Obviously, you can grab any ol' color scheme you like, but I like the fact that Solarized has light and dark modes, an easy way to switch between the two, and it's not too intrusive. My second choice is [Monokai](https://github.com/sickill/vim-monokai). The Volt plugin manager makes it easy for me to switch between the two, so I can use Monokai for Python programming and Solarized for Bash.

I'm not including an image for Solarized, because all the other images in this article use Solarized light or dark, so check them out.

## 7. fzf

When you're looking for a file, sometimes you want a file explorer, and sometimes you just want to ram something on your keyboard that vaguely resembles the filename you are looking for, amirite?

The [fzf](https://github.com/junegunn/fzf.vim) (or "fuzzy finder") plugin gives you just that. Hit **:FZF** and start typing. An ever-shortening list will show you files that more or less match what you are looking for. I use this a lot, probably even more than NERDTree these days. A slight downside is that this plugin has an external dependency in the fzf binary, so you'll have to install that, too. It's available for Fedora, Debian and, Arch, but I don't think it exists for EPEL.

![fzf Vim plugin fzf Vim plugin](https://opensource.com/sites/default/files/uploads/fzf.gif)

## 8. ack

Every once in a while, you want to search for a file that contains a certain line or a certain word. I really like the [ack](https://github.com/mileszs/ack.vim) plugin for this, preferably in combination with **ag**, a command known as "the [silver searcher](https://github.com/ggreer/the_silver_searcher)." This combination is phenomenally fast and covers the vast majority of things I would use **grep** or **vimgrep** for. The downside is you'll need to install either ack or ag for it to work. The good news is that both ag and ack are available for Fedora and EPEL7.

![ack vim plugin ack vim plugin](https://opensource.com/sites/default/files/uploads/ack.gif)

## 9. gitgutter

The majority of IT folks have worked with [Git](https://opensource.com/resources/what-is-git) and files in Git repositories. The [gitgutter](https://github.com/airblade/vim-gitgutter) plugin adds a column near your line numbers that shows symbols for changed (**~**), added (**+**), and removed (**-**) lines. This is quite useful for keeping track of what you have changed, and it keeps you focused on the task at hand, like writing a patch to fix one key bug. This plugin has a slight performance gap, and it sometimes takes a quick second for the plugin to catch up with your changes, but it's still quite useful.

![gitgutter vim plugin gitgutter vim plugin](https://opensource.com/sites/default/files/uploads/gitgutter.png)

## 10. Tag List

If you are programming in a file of any significant size, it's easy to lose track of where you are, and you might find yourself scrolling up and down looking for a certain function. With the [Tag List](https://github.com/vim-scripts/taglist.vim) plugin, you can just type **:Tlist** and get a vertical split with variables, types, classes, and functions that you can easily jump to. This works for a host of languages, like Java, Python, and any other file type the **ctags** utility works with … which is a lot.

![Tag List vim plugin Tag List vim plugin](https://opensource.com/sites/default/files/uploads/taglist.gif)

So there you are: the 10 plugins for Vim that have made my life as a sysadmin and part-time programmer a little easier and a little better. What Vim plugins you are using? Please share your favorites in the comments.

## 4 Comments