vim插件管理器vim-plug
虽然配置好了 Neovim ,并且工作良好,但是对于 Vim 也不想停留在过去的水平,所以同样升级了 Vim 的配置,首先将插件管理器由 Vundle 切换为 vim-plug ,其安装及使用方法请参考官方 README.md 文件内容。
由于网络问题,访问github
并不稳定,在配置插件时已经使用git@github.com:
全面取代了https://github.com/
,
但是对于插件vim-pug
自己升级的问题并没有很好的解决,因为其默认是从https://github.com/
下载自己的,相比较而言,neovim
下的packer
就要好的多,因为它可以自己管理自己。解决此问题的方法,暂时定为:
找到
plug.vim
第95行~/.vim/autoload/plug.vim 1
let s:plug_src = 'https://github.com/junegunn/vim-plug.git'
修改为
~/.vim/autoload/plug.vim 1
let s:plug_src = 'git@github.com:junegunn/vim-plug.git'
升级后,此地址再次变回
https://github.com
, 所以每次升级时都要执行上述操作。如果官方改良了这个升级地址,则不需要自己修改了,但是貌似这个更改有点难度。
Pros.
- Easy to set up: Single file. No boilerplate code required.
- Easy to use: Concise, intuitive syntax
- Super-fast
parallel installation/update (with any of
+job
,+python
,+python3
,+ruby
, or Neovim) - Creates shallow clones to minimize disk space usage and download time
- On-demand loading for faster startup time
- Can review and rollback updates
- Branch/tag/commit support
- Post-update hooks
- Support for externally managed plugins
Installation
Download plug.vim and put it in the "autoload" directory.
Vim
Unix
1 | curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ |
You can automate the process by putting the command in your Vim configuration file as suggested here.
Windows (PowerShell)
1 | iwr -useb https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim |` |
Neovim
Unix, Linux
1 | sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \ |
Linux (Flatpak)
1 | curl -fLo ~/.var/app/io.neovim.nvim/data/nvim/site/autoload/plug.vim --create-dirs \ |
Windows (PowerShell)
1 | iwr -useb https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim |` |
Getting Help
- See tutorial page to learn the basics of vim-plug
- See tips and FAQ pages for common problems and questions
- See requirements page for debugging information & tested configurations
- Create an issue
Usage
Add a vim-plug section to your ~/.vimrc
(or
stdpath('config') . '/init.vim'
for Neovim)
- Begin the section with
call plug#begin([PLUGIN_DIR])
- List the plugins with
Plug
commands call plug#end()
to update&runtimepath
and initialize plugin system- Automatically executes
filetype plugin indent on
andsyntax enable
. You can revert the settings after the call. e.g.filetype indent off
,syntax off
, etc.
- Automatically executes
Example
1 | call plug#begin() |
Reload .vimrc and :PlugInstall
to install plugins.
Commands
Command | Description |
---|---|
PlugInstall [name ...] [#threads] |
Install plugins |
PlugUpdate [name ...] [#threads] |
Install or update plugins |
PlugClean[!] |
Remove unlisted plugins (bang version will clean without prompt) |
PlugUpgrade |
Upgrade vim-plug itself |
PlugStatus |
Check the status of plugins |
PlugDiff |
Examine changes from the previous update and the pending changes |
PlugSnapshot[!] [output path] |
Generate script for restoring the current snapshot of the plugins |
Plug
options
Option | Description |
---|---|
branch /tag /commit |
Branch/tag/commit of the repository to use |
rtp |
Subdirectory that contains Vim plugin |
dir |
Custom directory for the plugin |
as |
Use different name for the plugin |
do |
Post-update hook (string or funcref) |
on |
On-demand loading: Commands or
<Plug> -mappings |
for |
On-demand loading: File types |
frozen |
Do not update unless explicitly specified |
Global options
Flag | Default | Description |
---|---|---|
g:plug_threads |
16 | Default number of threads to use |
g:plug_timeout |
60 | Time limit of each task in seconds (Ruby & Python) |
g:plug_retries |
2 | Number of retries in case of timeout (Ruby & Python) |
g:plug_shallow |
1 | Use shallow clone |
g:plug_window |
vertical topleft new |
Command to open plug window |
g:plug_pwindow |
above 12new |
Command to open preview window in PlugDiff |
g:plug_url_format |
https://git::@github.com/%s.git |
printf format to build repo URL (Only applies to the
subsequent Plug commands) |
Keybindings
D
-PlugDiff
S
-PlugStatus
R
- Retry failed update or installation tasksU
- Update plugins in the selected rangeq
- Close the window:PlugStatus
L
- Load plugin
:PlugDiff
X
- Revert the update
Example: A small sensible Vim configuration
1 | call plug#begin() |
On-demand loading of plugins
1 | " NERD tree will be loaded on the first invocation of NERDTreeToggle command |
The for
option is generally not needed as most plugins
for specific file types usually don't have too much code in the
plugin
directory. You might want to examine the output of
vim --startuptime
before applying the option.
Post-update hooks
There are some plugins that require extra steps after installation or
update. In that case, use the do
option to describe the
task to be performed.
1 | Plug 'Shougo/vimproc.vim', { 'do': 'make' } |
If the value starts with :
, it will be recognized as a
Vim command.
1 | Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' } |
If you need more control, you can pass a reference to a Vim function that takes a single argument.
1 | function! BuildYCM(info) |
Both forms of post-update hook are executed inside the directory of
the plugin and only run when the repository has changed, but you can
force it to run unconditionally with the bang-versions of the commands:
PlugInstall!
and PlugUpdate!
.
Make sure to escape BARs and double-quotes when you write the
do
option inline as they are mistakenly recognized as
command separator or the start of the trailing comment.
1 | Plug 'junegunn/fzf', { 'do': 'yes \| ./install' } |
But you can avoid the escaping if you extract the inline specification using a variable (or any Vimscript expression) as follows:
1 | let g:fzf_install = 'yes | ./install' |
PlugInstall!
and
PlugUpdate!
The installer takes the following steps when installing/updating a plugin:
git clone
orgit fetch
from its origin- Check out branch, tag, or commit and optionally
git merge
remote branch - If the plugin was updated (or installed for the first time)
- Update submodules
- Execute post-update hooks
The commands with the !
suffix ensure that all steps are
run unconditionally.
Articles
- Writing my own Vim plugin manager
- Vim plugins and startup time
Thoughts on Vim plugin dependency- Support for Plugfile has been removed since 0.5.0
Collaborators
- Jan Edmund Lazo - Windows support
- Jeremy Pallats - Python installer
License
MIT