[完成翻译] Useful Vim editor plugins for software developers - part 1

This commit is contained in:
GHLandy 2016-10-20 14:17:34 +00:00
parent 2f5dd31c52
commit dfce8c763f
2 changed files with 149 additions and 152 deletions

View File

@ -1,152 +0,0 @@
GHLandy Translating
Useful Vim editor plugins for software developers - part 1
============
An improved version of Vi, [Vim][31] is unarguably one of the most popular command line-based text editors in Linux. Besides being a feature-rich text editor, Vim is also used as an IDE (Integrated Development Environment) by software developers around the world.
What makes Vim really powerful is the fact that it's functionality can be extended through plugins. And needless to say, there exist several Vim plugins that are aimed at enhancing users' programming experience.
Especially for software developers who are new to Vim, and are using the editor for development purposes, we'll be discussing some useful Vim plugins - along with examples - in this tutorial.
Please note that all the examples, commands, and instructions mentioned in this tutorial have been tested on Ubuntu 16.04, and the Vim version we've used is 7.4.
### Plugin installation setup
Given that the tutorial is aimed at new users, it would be reasonable to assume that they don't know how Vim plugins are installed. So, first up, here are the steps required to complete the installation setup:
* Create a directory dubbed .vim in your home directory, and then create two sub-directories named autoload and bundle.
* Then, inside the autoload directory, you need to place a file named [pathogen.vim][20], which you can download from [here][19].
* Finally, create a file named .vimrc in your home directory and add the following two lines to it:
```
call pathogen#infect()
```
[![Vim plugin installation](https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/vimplugins-vimrc.png)][30]
That's it. You are now ready to install Vim plugins.
Note: Here we've discussed Vim plugin management using Pathogen. There are other plugin managers available as well - to get started, visit [this thread][29].
Now that we are all set, let's discuss a couple of useful Vim plugins.
### Vim Tagbar plugin
First up is the Tagbar plugin. This plugin gives you an overview of the structure of a source file by letting you browse the tags it contains. "It does this by creating a sidebar that displays the ctags-generated tags of the current file, ordered by their scope," the [plug-in's official website][28] says. "This means that for example methods in C++ are displayed under the class they are defined in."
Sounds cool, right? Now, lets see how you can install it.
Tagbar's installation is pretty easy - all you have to do is to run the following two commands:
```
cd ~/.vim/bundle/
git clone git://github.com/majutsushi/tagbar
```
After the plugin is installed, it's ready for use. You can test it out by opening a .cpp file in Vim, entering [the command mode][27], and running the:TagbarOpen command. Following is an example screenshot showing the sidebar (towards right) that comes up when the :TagbarOpen Vim command was executed:
[![Vim tagbar plugin](https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/vimplugins-tagbar-example.png)][26]
To close the sidebar, use the :TagbarClose command. What's worth mentioning here is that you can use the :TagbarOpen fj command to open the sidebar as well as shift control to it. This way, you can easily browse the tags it contains - pressing the Enter key on a tag brings up (and shifts control to) the corresponding function in the source code window on the left.
[![TagbarClose and TagbarOpen](https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/vimplugins-tagbar-ex2.png)][25]
In case you want to repeatedly open and close the sidebar, you can use the :TagbarToggle command instead of using :TagbarOpen and:TagbarClose, respectively.
If typing these commands seems time consuming to you, then you can create a shortcut for the :TagbarToggle command. For example, if you put the following line in your .vimrc file:
```
nmap <F8> :TagbarToggle<CR>
```
Moving on, sometimes you'll observe that certain tags are pre-fixed with a +, -, or # symbol. For example, the following screenshot (taken from the plugin's official website) shows some tags prefixed with a + symbol.
[![Toggle Tagbar window](https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/vimplugins-tagbar-visibility.png)][24]
These symbols basically depict the visibility information for a particular tag. Specifically, + indicates that the member is public, while - indicates a private member. The # symbol, on the other hand, indicates that the member is protected.
Following are some of the important points related to Tagbar:
* The plugin website makes it clear that "Tagbar is not a general-purpose tool for managing tags files. It only creates the tags it needs on-the-fly in-memory without creating any files. tags file management is provided by other plugins."
* Vim versions < 7.0.167 have a compatibility issue with Tagbar. "If you are affected by this use this alternate Tagbar download instead: [zip][18]," the website says. "It is on par with version 2.2 but probably won't be updated after that due to the amount of changes required."
* If you encounter the error Tagbar: Exuberant ctags not found! while launching the plugin, then you can fix it by downloading and installing ctags from[here][17].
* For more information on Tagbar, head [here][16].
### Vim delimitMate Plugin
The next plugin we'll be discussing here is delimitMate. The plugin basically provides insert mode auto-completion for quotes, parens, brackets, and more.
It also offers "some other related features that should make your time in insert mode a little bit easier, like syntax awareness (will not insert the closing delimiter in comments and other configurable regions), and expansions (off by default), and some more," the [plugin's official github page][23] says.
Installation of this plugin is similar to the way we installed the previous one:
```
cd ~/.vim/bundle/
git clone git://github.com/Raimondi/delimitMate.git
```
Once the plugin is installed successfully (meaning the above commands are successful), you don't have to do anything else - it loads automatically when the Vim editor is launched.
Now, whenever - while in Vim - you type a double quote, single quote, brace, parentheses, or bracket, they'll be automatically completed. 
The delimitMate plugin is configurable. For example, you can extend the list of supported symbols, prevent the plugin from loading automatically, turns off the plugin for certain file types, and more. To learn how to configure delimitMate to do all this (and much more), go through the plugin's detailed documentation, which you can access by running the :help delimitMate command.
The aforementioned command will split your Vim window horizontally into two, with the upper part containing the said documentation.
[![Vim deliMate Plugin](https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/vimplugins-delimitmate-help.png)][22]
### Conclusion
Of the two plugins mentioned in this article, Tagbar - you'll likely agree - requires comparatively more time to get used to. But once it's setup properly (meaning you have things like shortcut launch keys in place), it's a breeze to use. delimitMate, on the other hand, doesn't require you to remember anything. 
The tutorial would have given you an idea how useful Vim plugins can be. Apart from the ones discussed here, there are many more plugins available for software developers. We'll discuss a selected bunch in the next part. Meanwhile, drop in a comment if you use a cool development-related Vim plugin and want others to know about it.
In part 2 of this tutorial series I will cover the [Syntax highlighting plugin Syntastic][21].
--------------------------------------------------------------------------------
via: https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers/
作者:[Ansh][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers/
[1]:https://www.youtube.com/channel/UCOfXyFkINXf_e9XNosTJZDw
[2]:https://www.youtube.com/user/desainew
[3]:https://www.youtube.com/channel/UCEQXp_fcqwPcqrzNtWJ1w9w
[4]:http://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ffreedompenguin.com%2Farticles%2Fopinion%2Fopen-source-design-thing%2F
[5]:http://twitter.com/intent/tweet/?text=Is+Open+Source+Design+a+Thing%3F&url=https%3A%2F%2Ffreedompenguin.com%2Farticles%2Fopinion%2Fopen-source-design-thing%2F
[6]:https://plus.google.com/share?url=https%3A%2F%2Ffreedompenguin.com%2Farticles%2Fopinion%2Fopen-source-design-thing%2F
[7]:https://atom.io/
[8]:http://froont.com/
[9]:https://webflow.com/
[10]:https://gravit.io/
[11]:http://getbootstrap.com/
[12]:https://inkscape.org/en/
[13]:https://www.gimp.org/
[14]:https://en.wikipedia.org/wiki/Free_and_open-source_software
[15]:https://medium.com/dawn-capital/why-leverage-the-power-of-open-source-to-build-a-successful-software-business-8aba6f665bc4#.ggmn2ojxp
[16]:https://github.com/majutsushi/tagbar
[17]:http://ctags.sourceforge.net/
[18]:https://github.com/majutsushi/tagbar/zipball/70fix
[19]:https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim
[20]:http://www.vim.org/scripts/script.php?script_id=2332
[21]:https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-2-syntastic/
[22]:https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/big/vimplugins-delimitmate-help.png
[23]:https://github.com/Raimondi/delimitMate
[24]:https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/big/vimplugins-tagbar-visibility.png
[25]:https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/big/vimplugins-tagbar-ex2.png
[26]:https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/big/vimplugins-tagbar-example.png
[27]:http://www.tldp.org/LDP/intro-linux/html/sect_06_02.html
[28]:http://majutsushi.github.io/tagbar/
[29]:http://vi.stackexchange.com/questions/388/what-is-the-difference-between-the-vim-plugin-managers
[30]:https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/big/vimplugins-vimrc.png
[31]:http://www.vim.org/

View File

@ -0,0 +1,149 @@
开发者的实用 Vim 插件——第一部分
============
作为 Vi 的升级版,[Vim][31] 毫无争议是 Linux 中最受欢迎的命令行编辑器之一。除了是一个多功能编辑器外,世界各地的软件开发者将 Vim 当做 IDEIntegrated Development Environment集成开发环境来使用。
事实上,是 Vim 可以通过插件来扩展其自身功能才使得它如此功能强大。不用说,肯定有那么几个 Vim 插件是指在提高用户的编程体验的。
特别是对于刚刚使用 Vim 或者使用 Vim 做开发的的软件开发者来说,我们将在本教程中讨论一些非常有用的 Vim 插件,具体请看例示。
请注意:本教程中列举的所有例示、命令和说明都是在 Ubuntu 16.04 环境下进行测试的,并且,我们使用的 Vim 版本是 7.4。
### 插件安装设置
这是为新用户准备的,假设他们不知道如何安装 Vim 插件。所以,首先,就是给出一些完成安装设置的步骤。
* 在家目录下创建 .vim 目录,并在其中创建子目录 autoload 和 bundle。
* 然后,在 autoload 放置 [pathogen.vim][20] 文件,这个文件可以从 [此处][19] 下载。
* 最后,在家目录创建 .vimrc 文件,并添加一下内容。
```
call pathogen#infect()
```
[![Vim plugin installation](https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/vimplugins-vimrc.png)][30]
至此,你已完成了 Vim 插件安装的准备工作。
注意:我们已经讨论了使用 Pathogen 管理 Vim 插件。当然还有其他的插件管理工具——欲了解,请访问 [此处][29]。
现在已经全部设置完毕,就让我们来讨论两个好用的 Vim 插件吧。
### Vim 标签侧边栏Tagbar插件
首先就是标签侧边栏Tagbar插件。该插件能够让你浏览源文件包含的标签从而提供该源文件的就够简览。[官网的插件说明][28] 是这样说的“它通过创建侧边栏然后以一定顺序展示从当前文件提取的标签tags来完成这一功能。这意味着比如C++ 中的方法将展示在其自身所定义在的类里边。”
听起来很酷,不是吗?让我们来看看该怎么安装它。
标签侧边栏Tagbar的安装过程是相当容易的——你只需要运行下列命令
```
cd ~/.vim/bundle/
git clone git://github.com/majutsushi/tagbar
```
安装完之后就可以使用了,你可以在 Vim 中打开一个 .cpp 文件来测试它:进入[命令模式][27],然后运行 :TagbarOpen 命令。以下是运行 :TagbarOpen 命令之后出现侧边栏(右侧) 的效果图。
[![Vim tagbar plugin](https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/vimplugins-tagbar-example.png)][26]
使用 :TagbarClose 可以关闭侧边栏。值得一提的是,可以使用 :TagbarOpen fj 命令打开侧边栏,和是使用 shift 键控制侧边栏的效果一样。也就是说你可以很方便的浏览当前文件包含的标签tags——在对应的标签tags上按下 Enter 键(使用 shift 键控制)跳转到左边源码的对应位置。
[![TagbarClose and TagbarOpen](https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/vimplugins-tagbar-ex2.png)][25]
假如你想要反复地开关侧边栏,你可以使用 :TagbarToggle 命令,而不用交替的使用 :TagbarOpen 和 :TagbarClose 命令。
如果你觉得输入这些命令很费时间,你可以为 :TagbarToggle 命令创建快捷键。比如,添加一下内容到 .vimrc 文件中:
```
nmap <F8> :TagbarToggle<CR>
```
再往下说有时候你可能会注意到某个标签tags前边有一个 +、- 或者 # 符号。比如,一下截图(取自该插件的官网)展示了一些前边有 + 号的标签tags
[![Toggle Tagbar window](https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/vimplugins-tagbar-visibility.png)][24]
这些符号基本是用来表名一个特殊标签的可视化信息。特别是 + 表示该类是 public 的,而 - 表示一个 private 类。# 则是是表示一个 protected 类。
以下是使用标签侧边栏Tagbar的一些注意事项
* 该插件的官网早就有说明“标签侧边栏Tagbar并非是管理标签tags文件而设计它只是在动态内存中创建所需的标签而非创建任何文件。标签tags文件的管理有其他插件提供支持。”
* 低于 7.0.167 版本的 Vim 和标签侧边栏Tagbar插件存在着一个兼容性问题。根据官网“如果你受到此问题的影响请使用体代替版[下载 zip 压缩包][18]。这是 2.2 版本的标准,但由于依赖变更的数量,它可能不会再升级。”
* 如果你再加载该插件是遇到这样的错误未找到足够的样式Exuberant ctags not found!)。你可以从 [此处][17] 下载并安装 ctags 来修复错误。
* 获取更多信息请访问 [这里][16]。
### Vim 符号自动补齐delimitMate插件
下一个要介绍的插件就是符号自动补齐delimitMate。该插件在 Vim 插入模式下提供引号、圆括号和方括号等符号自动补齐功能。
[该插件官网][23]:“它同时也提供一些相关的特性让你在输入模式下变得更加辩解,比如语法纠错(在注释区或者其他的可配置区不会自动插入界限符)、扩展名识别(默认关闭)等。”
安装步骤与之前介绍的相似:
```
cd ~/.vim/bundle/
git clone git://github.com/Raimondi/delimitMate.git
```
一旦你成功安装这个插件(即上述命令执行成功),你就不需要进行任何配置了——当 Vim 启动时会自动加载这个插件。
至此,在你使用 Vim 的任何时候,只要你输入一个双引号、单引号、单号、圆括号、方括号,它们都会自动补齐。 
你可以自己配置 符号自动补齐delimitMate。比如你可以添加需要自动补齐的符号列表阻止自动加载插件对指定类型文件关闭插件等。想来接如何配置这些或者其他更多的配置请阅读该插件的详细文档——运行 :help delimitMate 即可。
上述命令会将你的 Vim 窗口水平分割成两个,上边一个包含我们所说的文档。
[![Vim deliMate Plugin](https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/vimplugins-delimitmate-help.png)][22]
### 结论
本文之中提到的两个插件Tagbar 需要花费较多时间来适应——你应该会同样这个说法。但只要正确设置好它(这意味着你像是有了快捷键一样方便),就容易使用了。至于 delimitMate不需要任何要求就可以上手。
本教程就是向你展示 Vim 如何高效能的想法。除了本文中提及的,仍然还有许多开发者可用的插件,我们将在下一个部分进行讨论。假如你正在使用一个关于开发的 Vim 插件,并希望广为人知,请在下方留下评论。
我们将在本教程的第二部分讲到 [语法高亮插件Syntastic][21]。
--------------------------------------------------------------------------------
via: https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers/
作者:[Ansh][a]
译者:[GHLandy](https://github.com/GHLandy)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers/
[1]:https://www.youtube.com/channel/UCOfXyFkINXf_e9XNosTJZDw
[2]:https://www.youtube.com/user/desainew
[3]:https://www.youtube.com/channel/UCEQXp_fcqwPcqrzNtWJ1w9w
[4]:http://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ffreedompenguin.com%2Farticles%2Fopinion%2Fopen-source-design-thing%2F
[5]:http://twitter.com/intent/tweet/?text=Is+Open+Source+Design+a+Thing%3F&url=https%3A%2F%2Ffreedompenguin.com%2Farticles%2Fopinion%2Fopen-source-design-thing%2F
[6]:https://plus.google.com/share?url=https%3A%2F%2Ffreedompenguin.com%2Farticles%2Fopinion%2Fopen-source-design-thing%2F
[7]:https://atom.io/
[8]:http://froont.com/
[9]:https://webflow.com/
[10]:https://gravit.io/
[11]:http://getbootstrap.com/
[12]:https://inkscape.org/en/
[13]:https://www.gimp.org/
[14]:https://en.wikipedia.org/wiki/Free_and_open-source_software
[15]:https://medium.com/dawn-capital/why-leverage-the-power-of-open-source-to-build-a-successful-software-business-8aba6f665bc4#.ggmn2ojxp
[16]:https://github.com/majutsushi/tagbar
[17]:http://ctags.sourceforge.net/
[18]:https://github.com/majutsushi/tagbar/zipball/70fix
[19]:https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim
[20]:http://www.vim.org/scripts/script.php?script_id=2332
[21]:https://www.howtoforge.com/tutorial/vim-editor-plugins-for-software-developers-2-syntastic/
[22]:https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/big/vimplugins-delimitmate-help.png
[23]:https://github.com/Raimondi/delimitMate
[24]:https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/big/vimplugins-tagbar-visibility.png
[25]:https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/big/vimplugins-tagbar-ex2.png
[26]:https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/big/vimplugins-tagbar-example.png
[27]:http://www.tldp.org/LDP/intro-linux/html/sect_06_02.html
[28]:http://majutsushi.github.io/tagbar/
[29]:http://vi.stackexchange.com/questions/388/what-is-the-difference-between-the-vim-plugin-managers
[30]:https://www.howtoforge.com/images/vim-editor-plugins-for-software-developers/big/vimplugins-vimrc.png
[31]:http://www.vim.org/