Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2020-02-19 20:04:13 +08:00
commit 7214027197
4 changed files with 280 additions and 294 deletions

View File

@ -0,0 +1,113 @@
[#]: collector: (lujun9972)
[#]: translator: (wxy)
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-11908-1.html)
[#]: subject: (Use Vim to send email and check your calendar)
[#]: via: (https://opensource.com/article/20/1/vim-email-calendar)
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney)
使用 Vim 发送邮件和检查日历
======
> 在 2020 年用开源实现更高生产力的二十种方式的第十六篇文章中,直接通过文本编辑器管理你的电子邮件和日历。
![](https://img.linux.net.cn/data/attachment/album/202002/19/185842eyz2znxx1yc2ctnc.jpg)
去年,我在 19 天里给你介绍了 19 个新(对你而言)的生产力工具。今年,我换了一种方式:使用你在使用或者还没使用的工具,构建一个使你可以在新一年更加高效的环境。
### 用 Vim 做(几乎)所有事情,第一部分
我经常使用两个文本编辑器 —— [Vim][2] 和 [Emacs][3]。为什么两者都用呢?它们有不同的使用场景,在本系列的后续几篇文章中,我将讨论其中的一些用例。
![][4]
好吧,为什么要在 Vim 中执行所有操作?因为如果有一个应用程序是我可以访问的每台计算机上都有的,那就是 Vim。如果你像我一样可能已经在 Vim 中打发了很多时光。那么,为什么不将其用于**所有事情**呢?
但是,在此之前,你需要做一些事情。首先是确保你的 Vim 具有 Ruby 支持。你可以使用 `vim --version | grep ruby`。如果结果不是 `+ruby`,则需要解决这个问题。这可能有点麻烦,你应该查看发行版的文档以获取正确的软件包。在 MacOS 上,用的是官方的 MacVim不是 Brew 发行的),在大多数 Linux 发行版中,用的是 vim-nox 或 vim-gtk而不是 vim-gtk3。
我使用 [Pathogen][5] 自动加载插件和捆绑软件。如果你使用 [Vundle][6] 或其他 Vim 软件包管理器,则需要调整以下命令才能使用它。
#### 在 Vim 中管理你的邮件
使 Vim 在你的生产力计划中发挥更大作用的一个很好的起点是使用它通过 [Notmuch] [7] 发送和接收电子邮件,和使用 [abook] [8] 访问你的联系人列表。你需要为此安装一些东西。下面的所有示例代码都运行在 Ubuntu 上,因此如果你使用其他发行版,则需要对此进行调整。通过以下步骤进行设置:
```
sudo apt install notmuch-vim ruby-mail
curl -o ~/.vim/plugin/abook --create-dirs https://raw.githubusercontent.com/dcbaker/vim-abook/master/plugin/abook.vim
```
到目前为止,一切都很顺利。现在启动 Vim 并执行 `:NotMuch`。由于是用较旧版本的邮件库 `notmuch-vim` 编写的可能会出现一些警告但总的来说Vim 现在将成为功能齐全的 Notmuch 邮件客户端。
![Reading Mail in Vim][9]
如果要搜索特定标签,请输入 `\t`,输入标签名称,然后按回车。这将拉出一个带有该标签的所有消息的列表。`\s` 组合键会弹出 `Search:` 提示符,可以对 Notmuch 数据库进行全面搜索。使用箭头键浏览消息列表,按回车键显示所选项目,然后输入 `\q` 退出当前视图。
要撰写邮件,请使用 `\c` 按键。你将看到一条空白消息。这是 `abook.vim` 插件发挥作用的位置。按下 `Esc` 并输入 `:AbookQuery <SomeName>`,其中 `<SomeName>` 是你要查找的名称或电子邮件地址的一部分。你将在 abook 数据库中找到与你的搜索匹配的条目列表。通过键入你想要的地址的编号,将其添加到电子邮件的地址行中。完成电子邮件的键入和编辑,按 `Esc` 退出编辑模式,然后输入 `,s` 发送。
如果要在 `:NotMuch` 启动时更改默认文件夹视图,则可以将变量 `g:notmuch_folders` 添加到你的 `.vimrc` 文件中:
```
let g:notmuch_folders = [
\ [ 'new', 'tag:inbox and tag:unread' ],
\ [ 'inbox', 'tag:inbox' ],
\ [ 'unread', 'tag:unread' ],
\ [ 'News', 'tag:@sanenews' ],
\ [ 'Later', 'tag:@sanelater' ],
\ [ 'Patreon', 'tag:@patreon' ],
\ [ 'LivestockConservancy', 'tag:livestock-conservancy' ],
\ ]
```
Notmuch 插件的文档中涵盖了更多设置,包括设置标签键和使用其它的邮件程序。
#### 在 Vim 中查询日历
![][10]
遗憾的是,似乎没有使用 vCalendar 或 iCalendar 格式的 Vim 日历程序。有个 [Calendar.vim][11],做得很好。设置 Vim 通过以下方式访问你的日历:
```
cd ~/.vim/bundle
git clone git@github.com:itchyny/calendar.vim.git
```
现在,你可以通过输入 `:Calendar` 在 Vim 中查看日历。你可以使用 `<``>` 键在年、月、周、日和时钟视图之间切换。如果要从一个特定的视图开始,请使用 `-view=` 标志告诉它你希望看到哪个视图。你也可以在任何视图中定位日期。例如,如果我想查看 2020 年 7 月 4 日这一周的情况,请输入 `:Calendar -view week 7 4 2020`。它的帮助信息非常好,可以使用 `?` 键参看。
![][13]
Calendar.vim 还支持 Google Calendar我需要但是在 2019 年 12 月Google 禁用了它的访问权限。作者已在 [GitHub 上的这个提案][14]中发布了一种变通方法。
这样你就在 Vim 中有了这些:你的邮件、地址簿和日历。但是这些还没有完成; 下一篇你将在 Vim 上做更多的事情!
Vim 为作家提供了很多好处,无论他们是否具有技术意识。
需要保持时间表正确吗?了解如何使用这些免费的开源软件来做到这一点。
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/1/vim-email-calendar
作者:[Kevin Sonney][a]
选题:[lujun9972][b]
译者:[wxy](https://github.com/wxy)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/ksonney
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/calendar.jpg?itok=jEKbhvDT (Calendar close up snapshot)
[2]: https://www.vim.org/
[3]: https://www.gnu.org/software/emacs/
[4]: https://opensource.com/sites/default/files/uploads/day16-image1.png
[5]: https://github.com/tpope/vim-pathogen
[6]: https://github.com/VundleVim/Vundle.vim
[7]: https://opensource.com/article/20/1/organize-email-notmuch
[8]: https://opensource.com/article/20/1/sync-contacts-locally
[9]: https://opensource.com/sites/default/files/uploads/productivity_16-2.png (Reading Mail in Vim)
[10]: https://opensource.com/sites/default/files/uploads/day16-image3.png
[11]: https://github.com/itchyny/calendar.vim
[12]: mailto:git@github.com
[13]: https://opensource.com/sites/default/files/uploads/day16-image4.png
[14]: https://github.com/itchyny/calendar.vim/issues/156

View File

@ -1,117 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Use Vim to send email and check your calendar)
[#]: via: (https://opensource.com/article/20/1/vim-email-calendar)
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney)
Use Vim to send email and check your calendar
======
Manage your email and calendar right from your text editor in the
sixteenth in our series on 20 ways to be more productive with open
source in 2020.
![Calendar close up snapshot][1]
Last year, I brought you 19 days of new (to you) productivity tools for 2019. This year, I'm taking a different approach: building an environment that will allow you to be more productive in the new year, using tools you may or may not already be using.
### Doing (almost) all the things with Vim, part 1
I use two text editors regularly—[Vim][2] and [Emacs][3]. Why both? They have different use cases, and I'll talk about some of them in the next few articles in this series.
![][4]
OK, so why do everything in Vim? Because if there is one application that is on every machine I have access to, it's Vim. And if you are like me, you probably already spend a lot of time in Vim. So why not use it for _all the things_?
Before that, though, you need to do some things. The first is to make sure you have Ruby support in Vim. You can check that with **vim --version | grep ruby**. If the result is not **+ruby**, that needs to be fixed. This can be tricky, and you should check your distribution's documentation for the right package to install. On MacOS, this is the official MacVim (not from Brew), and on most Linux distributions, this is either vim-nox or vim-gtk—NOT vim-gtk3.
I use [Pathogen][5] to autoload my plugins and bundles. If you use [Vundle][6] or another Vim package manager, you'll need to adjust the commands below to work with it.
#### Do your email in Vim
A good starting place for making Vim a bigger part of your productivity plan is using it to send and receive email with [Notmuch][7] using [abook][8] to access your contact list. You need to install some things for this. All the sample code below is on Ubuntu, so you'll need to adjust for that if you are using a different distribution. Do the setup with:
```
sudo apt install notmuch-vim ruby-mail
curl -o ~/.vim/plugin/abook --create-dirs <https://raw.githubusercontent.com/dcbaker/vim-abook/master/plugin/abook.vim>
```
So far, so good. Now start Vim and execute **:NotMuch**. There may be some warnings due to the older version of the mail library **notmuch-vim** was written for, but in general, Vim will now be a full-featured Notmuch mail client.
![Reading Mail in Vim][9]
If you want to perform a search for a specific tag, type **\t**, enter the name of the tag, and press Enter. This will pull up a list of all messages with that tag. The **\s** key combination brings up a **Search:** prompt that will do a full search of the Notmuch database. Navigate the message list with the arrow keys, press Enter to display the selected item, and enter **\q** to exit the current view.
To compose mail, use the **\c** keystroke. You will see a blank message. This is where the **abook.vim** plugin comes in. Hit **Esc** and enter **:AbookQuery &lt;SomeName&gt;**, where &lt;SomeName&gt; is a part of the name or email address you want to look for. You will get a list of entries in the abook database that match your search. Select the address you want by typing its number to add it to the email's address line. Finish typing and editing the email, press **Esc** to exit edit mode, and enter **,s** to send.
If you want to change the default folder view when **:NotMuch** starts up, you can add the variable **g:notmuch_folders** to your **.vimrc** file:
```
let g:notmuch_folders = [
      \ [ 'new', 'tag:inbox and tag:unread' ],
      \ [ 'inbox', 'tag:inbox' ],
      \ [ 'unread', 'tag:unread' ],
      \ [ 'News', 'tag:@sanenews' ],
      \ [ 'Later', 'tag:@sanelater' ],
      \ [ 'Patreon', 'tag:@patreon' ],
      \ [ 'LivestockConservancy', 'tag:livestock-conservancy' ],
    \ ]
```
There are many more settings covered in the Notmuch plugin's documentation, including setting up keys for tags and using alternate mail programs.
#### Consult your calendar in Vim
![][10]
Sadly, there do not appear to be any calendar programs for Vim that use the vCalendar or iCalendar formats. There is [Calendar.vim][11], which is very well done. Set up Vim to access your calendar with:
```
cd ~/.vim/bundle
git clone [git@github.com][12]:itchyny/calendar.vim.git
```
Now, you can see your calendar in Vim by entering **:Calendar**. You can switch between year, month, week, day, and clock views with the **&lt;** and **&gt;** keys. If you want to start with a particular view, use the **-view=** flag to tell it which one you wish to see. You can also add a date to any of the views. For example, if I want to see what is going on the week of July 4, 2020, I would enter **:Calendar -view week 7 4 2020**. The help is pretty good and can be accessed with the **?** key.
![][13]
Calendar.vim also supports Google Calendar (which I need), but in December 2019 Google disabled the access for it. The author has posted a workaround in [the issue on
GitHub][14].
So there you have it, your mail, addresses, and calendars in Vim. But you aren't done yet; you'll do even more with Vim tomorrow!
Vim offers great benefits to writers, regardless of whether they are technically minded or not.
Need to keep your schedule straight? Learn how to do it using open source with these free...
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/1/vim-email-calendar
作者:[Kevin Sonney][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/ksonney
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/calendar.jpg?itok=jEKbhvDT (Calendar close up snapshot)
[2]: https://www.vim.org/
[3]: https://www.gnu.org/software/emacs/
[4]: https://opensource.com/sites/default/files/uploads/day16-image1.png
[5]: https://github.com/tpope/vim-pathogen
[6]: https://github.com/VundleVim/Vundle.vim
[7]: https://opensource.com/article/20/1/organize-email-notmuch
[8]: https://opensource.com/article/20/1/sync-contacts-locally
[9]: https://opensource.com/sites/default/files/uploads/productivity_16-2.png (Reading Mail in Vim)
[10]: https://opensource.com/sites/default/files/uploads/day16-image3.png
[11]: https://github.com/itchyny/calendar.vim
[12]: mailto:git@github.com
[13]: https://opensource.com/sites/default/files/uploads/day16-image4.png
[14]: https://github.com/itchyny/calendar.vim/issues/156

View File

@ -1,177 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (qianmingtian)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to install Vim plugins)
[#]: via: (https://opensource.com/article/20/2/how-install-vim-plugins)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
How to install Vim plugins
======
Whether you install them manually or with a package manager, plugins can
help you create the perfect Vim for your workflow.
![Team checklist and to dos][1]
While [Vim][2] is fast and efficient, by default, it is but a mere text editor. At least, that's what it would be without plugins, which build upon Vim and add extra features to make it so much more than just a window for typing text. With the right mix of plugins, you can take control of your life and forge your own unique Vim experience. You can [customize your theme][3], and you can add syntax highlighting, code linting, version trackers, and much much more.
### How to install Vim plugins
Vim is extensible through plugins, but for a long time, there was no official method for installing them. As of the Vim 8.x series, however, there's a structure around how plugins are intended to be installed and loaded. You may encounter old instructions online or in project README files, but as long as you're running Vim 8 or greater, you should install according to Vim's [official plugin install method][4] or with a Vim package manager. You can use a package manager regardless of what version you run (including releases older than 8.x), which makes the install process easier than maintaining updates yourself.
Both the manual and automated methods are worth knowing, so keep reading to learn about both.
### Install plugins manually (Vim 8 and above)
A Vim package is a directory containing one or more plugins. By default, your Vim settings are contained in **~/.vim**, so that's where Vim looks for plugins when you launch it. (The examples below use the generic name **vendor** to indicate that the plugins are obtained from an entity that is not you.)
When you start Vim, it first processes your **.vimrc** file, and then it scans all directories in **~/.vim** for plugins contained in **pack/*/start**.
By default, your **~/.vim** directory (if you even have one) has no such file structure, so set that up with:
```
`$ mkdir -p ~/.vim/pack/vendor/start`
```
Now you can place Vim plugins in **~/.vim/pack/vendor/start**, and they'll automatically load when you launch Vim.
For example, try installing [NERDTree][5], a text-based file manager for Vim. First, use Git to clone a snapshot of the NERDTree repository:
```
$ git clone --depth 1 \
  <https://github.com/preservim/nerdtree.git> \
  ~/.vim/pack/vendor/start/nerdtree
```
Launch Vim or gvim, and type this command:
```
`:NERDTree`
```
A file tree will open along the left side of your Vim window.
![NERDTree plugin][6]
If you don't want a plugin to load automatically every time you launch Vim, you can create an **opt** directory within your **~/.vim/pack/vendor** directory:
```
`$ mkdir ~/.vim/pack/vendor/opt`
```
Any plugins installed into **opt** are available to Vim but not loaded into memory until you add them to a session with the **packadd** command, e.g., for an imaginary plugin called foo:
```
`:packadd foo`
```
Officially, Vim recommends that each plugin project gets its own directory within **~/.vim/pack**. For example, if you were to install the NERDTree plugin and the imaginary foo plugin, you would create this structure:
```
$ mkdir -p ~/.vim/pack/NERDTree/start/
$ git clone --depth 1 \
  <https://github.com/preservim/nerdtree.git> \
  ~/.vim/pack/NERDTree/start/NERDTree
$ mkdir -p ~/.vim/pack/foo/start/
$ git clone --depth 1 \
  <https://notabug.org/foo/foo.git> \
  ~/.vim/pack/foo/start/foo
```
Whether that's convenient is up to you.
### Using a Vim package manager (any Vim version)
Since Vim series 8, package managers have become less useful, but some users still prefer them because of their ability to auto-update several plugins. There are several package managers to choose from, and they're each different, but [vim-plug][7] has some great features and the best documentation of them all, which makes it easy to start with and to explore in depth later.
#### Installing plugins with vim-plug
Install vim-plug so that it auto-loads at launch with:
```
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
  <https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim>
```
Create a **~/.vimrc** file (if you don't have one already), and enter this text:
```
call plug#begin()
Plug 'preservim/NERDTree'
call plug#end()
```
Each time you want to install a plugin, you must enter the name and location of the plugin between the **plug#begin()** and **plug#end** lines. (The NERDTree file manager is used above as an example.) If the plugin you want isn't hosted on GitHub, then you can provide the full URL instead of just the GitHub username and project ID. You can even "install" local plugins outside of your **~/.vim** directory.
Finally, start Vim and prompt vim-plug to install the plugins listed in **~/.vimrc**:
```
`:PlugInstall`
```
Wait for the plugins to be downloaded.
#### Update plugins with vim-plug
Editing **~/.vimrc** and issuing a command to do the installation probably doesn't seem like much of a savings over the manual install process, but the real benefit to vim-plug is in updates. To update all installed plugins, issue this Vim command:
```
`:PlugUpdate`
```
If you don't want to update all plugins, you can update any subset by adding the plugin's name:
```
`:PlugUpdate NERDTree`
```
#### Restore plugins
Another vim-plug benefit is its export and recovery function. As any Vim user knows, the way Vim works is often unique to each user—in part because of plugins. Once you get the right blend of plugins installed and configured, the last thing you want is to lose track of them.
Vim-plug has this command to generate a script for restoring all current plugins:
```
`:PlugSnapshot ~/vim-plug.list`
```
There are many other functions for vim-plug, so refer to its [project page][7] for the full documentation.
### Create the perfect Vim
When you spend all day in a program, you want every little detail to serve you the best it possibly can. Get to know Vim and its many plugins until you build the perfect application for what you do.
Got a favorite Vim plugin? Tell us all about it in the comments!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/2/how-install-vim-plugins
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/todo_checklist_team_metrics_report.png?itok=oB5uQbzf (Team checklist and to dos)
[2]: https://www.vim.org/
[3]: https://opensource.com/article/19/12/colors-themes-vim
[4]: https://github.com/vim/vim/blob/03c3bd9fd094c1aede2e8fe3ad8fd25b9f033053/runtime/doc/repeat.txt#L515
[5]: https://github.com/preservim/nerdtree
[6]: https://opensource.com/sites/default/files/uploads/vim-nerdtree.jpg (NERDTree plugin)
[7]: https://github.com/junegunn/vim-plug

View File

@ -0,0 +1,167 @@
[#]: collector: (lujun9972)
[#]: translator: (qianmingtian)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to install Vim plugins)
[#]: via: (https://opensource.com/article/20/2/how-install-vim-plugins)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
如何安装 Vim 插件
======
无论你是手动安装还是通过包管理器安装,插件都可以帮你为你的工作流中打造一个完美的 Vim 。
![Team checklist and to dos][1]
虽然 [Vim][2] 是快速且高效的,但在默认情况下,它仅仅只是一个文本编辑器。至少,这就是没有插件的情况 Vim 应当具备的样子,插件构建在 Vim 之上,并添加额外的功能,使 Vim 不仅仅是一个输入文本的窗口。有了合适的插件组合,你可以控制你的生活,形成你自己独特的 Vim 体验。你可以[自定义你的主题][3],你可以添加语法高亮,代码 linting ,版本跟踪器等等。
### 怎么安装 Vim 插件
Vim 可以通过插件进行扩展,但很长一段时间以来,并没有官方的安装方式去安装这些插件。从 Vim 8 开始,有一个关于插件如何安装和加载的结构。你可能会在网上或项目自述文件中遇到旧的说明,但只要你运行 Vim 8 或更高版本,你应该根据 Vim 的[官方插件安装方法][4]安装或使用 Vim 包管理器。您可以使用包管理器,无论你运行的是什么版本(包括比 8.x 更老的版本),这使得安装过程比您自己维护更新更容易。
手动和自动安装方法都值得了解,所以请继续阅读以了解这两种方法。
### 手动安装插件( Vim 8 及以上版本)
Vim 包是一个包含一个或多个插件的目录。默认情况下,你的 Vim 设置包含在 **~/.vim** 中,这是 vim 在启动时寻找插件的地方。(下面的示例使用了通用名称 **vendor** 来表示插件是从一个不是你的实体获得的。)
当你启动 Vim 时,它首先处理你的 **.vimrc**文件,然后扫描 **~/.vim** 中的所有目录查找包含在 **pack/*/start** 中的插件。
默认情况下,你的 **~/.vim** 目录(如果你有一个)没有这样的文件结构,所以设置为:
```
`$ mkdir -p ~/.vim/pack/vendor/start`
```
现在,你可以将 Vim 插件放在 **~/.vim/pack/vendor/start** 中,它们会在你启动 Vim 时自动加载。
例如,尝试安装一下 [NERDTree][5] ,一个基于文本的 Vim 文件管理器。首先,使用 Git 克隆 NERDTree 存储库的快照:
```
$ git clone --depth 1 \
  <https://github.com/preservim/nerdtree.git> \
  ~/.vim/pack/vendor/start/nerdtree
```
启动 Vim 或者 gvim ,然后键入如下命令:
```
`:NERDTree`
```
Vim 窗口左侧将打开一个文件树。
![NERDTree plugin][6]
如果你不想每次启动 Vim 时自动加载插件,你可以在 **~/.vim/pack/vendor** 中创建 **opt** 文件夹:
```
`$ mkdir ~/.vim/pack/vendor/opt`
```
任何安装到 **opt** 的插件都可被 Vim 使用,但是只有当你使用 **packadd** 命令将它们添加到一个会话中时,它们才会被加载到内存中。例如,一个虚构的叫 foo 的插件:
```
`:packadd foo`
```
Vim 官方建议每个插件项目在 **~/.Vim /pack** 中有自己的目录。例如,如果你要安装 NERDTree 插件和假想的 foo 插件,你需要创建这样的目录结构:
```
$ mkdir -p ~/.vim/pack/NERDTree/start/
$ git clone --depth 1 \
  <https://github.com/preservim/nerdtree.git> \
  ~/.vim/pack/NERDTree/start/NERDTree
$ mkdir -p ~/.vim/pack/foo/start/
$ git clone --depth 1 \
  <https://notabug.org/foo/foo.git> \
  ~/.vim/pack/foo/start/foo
```
这样做是否方便取决于你。
### 使用 Vim 包管理器(任何 Vim 版本)
自从 Vim 8 以后,包管理器变得不那么有用了,但是一些用户仍然喜欢它们,因为它们能够自动更新一些插件。有几个包管理器可供选择,并且它们各不相同,但是 [vim-plug][7] 有一些很棒的特性和最好的文档,这使我们很容易开始并在以后深入研究。
#### 使用 vim-plug 安装插件
安装 vim-plug ,以便它在启动时自动加载:
```
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
  <https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim>
```
创建一个 **~/.vimrc** 文件(如果你还没有文件),然后输入以下文本:
```
call plug#begin()
Plug 'preservim/NERDTree'
call plug#end()
```
每次要安装插件时,都必须在 **plugbegin()****plugend()** 之间输入插件的名称和位置(上面以 NERDTree 文件管理器为例。)。如果你所需的插件未托管在 GitHub 上,你可以提供完整的 URL ,而不仅仅是 GitHub 用户名和项目 ID 。你甚至可以在 **~/.vim** 目录之外“安装”本地插件。
最后,启动 Vim 并提示 vim-plug 安装 **~/.vimrc** 中列出的插件:
```
`:PlugInstall`
```
等待插件下载。
#### 通过 vim-plug 更新插件
与手动安装过程相比,编辑 **~/.vimrc** 并使用命令来进行安装可能看起来并没有多省事,但是 vim-plug 的真正优势在更新。更新所有安装的插件,使用这个 Vim 命令:
```
`:PlugUpdate`
```
如果你不想更新所有的插件,你可以通过添加插件的名字来更新任何插件:
```
`:PlugUpdate NERDTree`
```
#### 恢复插件
vim-plug 的另一个优点是它的导出和恢复功能。 Vim 用户都知道,正是插件的缘故,通常每个用户使用 Vim 的工作方式都是独一无二的。一旦你安装和配置了正确的插件组合,你最不想要的就是再也找不到它们。
Vim-plug 有这个命令来生成一个脚本来恢复所有当前的插件:
```
`:PlugSnapshot ~/vim-plug.list`
```
vim-plug 还有许多其他的功能,所以请参考它的[项目页面][7]以获得完整的文档。
### 打造一个完美的 Vim
当你整天都在做一个项目时,你希望每一个小细节都能为你提供最好的服务。了解 Vim 和它的许多插件,直到你为你所做的事情构建出一个完美的应用程序。
有喜欢的 Vim 插件吗?请在评论中告诉我们吧!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/2/how-install-vim-plugins
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[qianmingtian][c]
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/seth
[b]: https://github.com/lujun9972
[c]: https://github.com/qianmingtian
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/todo_checklist_team_metrics_report.png?itok=oB5uQbzf (Team checklist and to dos)
[2]: https://www.vim.org/
[3]: https://opensource.com/article/19/12/colors-themes-vim
[4]: https://github.com/vim/vim/blob/03c3bd9fd094c1aede2e8fe3ad8fd25b9f033053/runtime/doc/repeat.txt#L515
[5]: https://github.com/preservim/nerdtree
[6]: https://opensource.com/sites/default/files/uploads/vim-nerdtree.jpg (NERDTree plugin)
[7]: https://github.com/junegunn/vim-plug