一个极简主义的 Vim 插件管理器。
下载plug.vim并将其放在“autoload”目录中。
curl -fLo ~ /.vim/autoload/plug.vim --create-dirs
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
您可以按照此处的建议将命令放入 Vim 配置文件中来自动化该过程。
iwr - useb https: // raw.githubusercontent.com / junegunn / vim - plug / master / plug.vim |`
ni $HOME / vimfiles / autoload / plug.vim - Force
sh -c ' curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim '
curl -fLo ~ /.var/app/io.neovim.nvim/data/nvim/site/autoload/plug.vim --create-dirs
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
iwr - useb https: // raw.githubusercontent.com / junegunn / vim - plug / master / plug.vim |`
ni " $ ( @ ( $ env: XDG_DATA_HOME , $ env: LOCALAPPDATA )[ $null -eq $ env: XDG_DATA_HOME ] ) /nvim-data/site/autoload/plug.vim " - Force
将 vim-plug 部分添加到~/.vimrc
(或 Neovim 的~/.config/nvim/init.vim
)
call plug#begin()
开始该部分Plug
命令列出插件call plug#end()
结束该部分例如,
call plug#begin ()
" List your plugins here
Plug ' tpope/vim-sensible '
call plug#end ()
重新加载文件或者重启Vim,然后就可以了,
:PlugInstall
安装插件:PlugUpdate
安装或更新插件:PlugDiff
查看上次更新后的更改:PlugClean
删除列表中不再存在的插件笔记
这基本上就是您开始时需要了解的全部内容。本文档的其余部分适用于想要了解更多功能和选项的高级用户。
提示
plug#end()
自动执行filetype plugin indent on
和syntax enable
。我们相信这对于大多数用户来说是一个很好的默认设置,但如果您不希望出现这种行为,您可以在调用后恢复设置。
call plug#end ()
filetype indent off " Disable file-type-specific indentation
syntax off " Disable syntax highlighting
以下示例演示了 vim-plug 的附加功能。
call plug#begin ()
" The default plugin directory will be as follows:
" - Vim (Linux/macOS): '~/.vim/plugged'
" - Vim (Windows): '~/vimfiles/plugged'
" - Neovim (Linux/macOS/Windows): stdpath('data') . '/plugged'
" You can specify a custom plugin directory by passing it as the argument
" - e.g. `call plug#begin('~/.vim/plugged')`
" - Avoid using standard Vim directory names like 'plugin'
" Make sure you use single quotes
" Shorthand notation for GitHub; translates to https://github.com/junegunn/seoul256.vim.git
Plug ' junegunn/seoul256.vim '
" Any valid git URL is allowed
Plug ' https://github.com/junegunn/vim-easy-align.git '
" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug ' fatih/vim-go ' , { ' tag ' : ' * ' }
" Using a non-default branch
Plug ' neoclide/coc.nvim ' , { ' branch ' : ' release ' }
" Use 'dir' option to install plugin in a non-default directory
Plug ' junegunn/fzf ' , { ' dir ' : ' ~/.fzf ' }
" Post-update hook: run a shell command after installing or updating the plugin
Plug ' junegunn/fzf ' , { ' dir ' : ' ~/.fzf ' , ' do ' : ' ./install --all ' }
" Post-update hook can be a lambda expression
Plug ' junegunn/fzf ' , { ' do ' : { - > fzf#install () } }
" If the vim plugin is in a subdirectory, use 'rtp' option to specify its path
Plug ' nsf/gocode ' , { ' rtp ' : ' vim ' }
" On-demand loading: loaded when the specified command is executed
Plug ' preservim/nerdtree ' , { ' on ' : ' NERDTreeToggle ' }
" On-demand loading: loaded when a file with a specific file type is opened
Plug ' tpope/vim-fireplace ' , { ' for ' : ' clojure ' }
" Unmanaged plugin (manually installed and updated)
Plug ' ~/my-prototype-plugin '
" Call plug#end to update &runtimepath and initialize the plugin system.
" - It automatically executes `filetype plugin indent on` and `syntax enable`
call plug#end ()
" You can revert the settings after the call like so:
" filetype indent off " Disable file-type-specific indentation
" syntax off " Disable syntax highlighting
" Color schemes should be loaded after plug#end().
" We prepend it with 'silent!' to ignore errors when it's not yet installed.
silent ! colorscheme seoul256
在 Neovim 中,您可以将配置写入名为init.lua
Lua 脚本文件中。以下代码是与上面的 Vim 脚本示例等效的 Lua 脚本。
local vim = vim
local Plug = vim . fn [ ' plug# ' ]
vim . call ( ' plug#begin ' )
-- Shorthand notation for GitHub; translates to https://github.com/junegunn/seoul256.vim.git
Plug ( ' junegunn/seoul256.vim ' )
-- Any valid git URL is allowed
Plug ( ' https://github.com/junegunn/vim-easy-align.git ' )
-- Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug ( ' fatih/vim-go ' , { [ ' tag ' ] = ' * ' })
-- Using a non-default branch
Plug ( ' neoclide/coc.nvim ' , { [ ' branch ' ] = ' release ' })
-- Use 'dir' option to install plugin in a non-default directory
Plug ( ' junegunn/fzf ' , { [ ' dir ' ] = ' ~/.fzf ' })
-- Post-update hook: run a shell command after installing or updating the plugin
Plug ( ' junegunn/fzf ' , { [ ' dir ' ] = ' ~/.fzf ' , [ ' do ' ] = ' ./install --all ' })
-- Post-update hook can be a lambda expression
Plug ( ' junegunn/fzf ' , { [ ' do ' ] = function ()
vim . fn [ ' fzf#install ' ]()
end })
-- If the vim plugin is in a subdirectory, use 'rtp' option to specify its path
Plug ( ' nsf/gocode ' , { [ ' rtp ' ] = ' vim ' })
-- On-demand loading: loaded when the specified command is executed
Plug ( ' preservim/nerdtree ' , { [ ' on ' ] = ' NERDTreeToggle ' })
-- On-demand loading: loaded when a file with a specific file type is opened
Plug ( ' tpope/vim-fireplace ' , { [ ' for ' ] = ' clojure ' })
-- Unmanaged plugin (manually installed and updated)
Plug ( ' ~/my-prototype-plugin ' )
vim . call ( ' plug#end ' )
-- Color schemes should be loaded after plug#end().
-- We prepend it with 'silent!' to ignore errors when it's not yet installed.
vim . cmd ( ' silent! colorscheme seoul256 ' )
命令 | 描述 |
---|---|
PlugInstall [name ...] [#threads] | 安装插件 |
PlugUpdate [name ...] [#threads] | 安装或更新插件 |
PlugClean[!] | 删除未列出的插件(bang版本将在没有提示的情况下清理) |
PlugUpgrade | 升级 vim-plug 本身 |
PlugStatus | 检查插件的状态 |
PlugDiff | 检查上次更新的更改和待处理的更改 |
PlugSnapshot[!] [output path] | 生成用于恢复插件当前快照的脚本 |
Plug
选项选项 | 描述 |
---|---|
branch / tag / commit | 要使用的存储库的分支/标签/提交 |
rtp | 包含 Vim 插件的子目录 |
dir | 插件的自定义目录 |
as | 为插件使用不同的名称 |
do | 更新后挂钩(字符串或 funcref) |
on | 按需加载:命令或<Plug> -mappings |
for | 按需加载:文件类型 |
frozen | 除非明确指定,否则不要删除和更新 |
旗帜 | 默认 | 描述 |
---|---|---|
g:plug_threads | 16 | 默认使用的线程数 |
g:plug_timeout | 60 | 每个任务的时间限制(以秒为单位)( Ruby 和 Python ) |
g:plug_retries | 2 | 超时时的重试次数( Ruby 和 Python ) |
g:plug_shallow | 1 | 使用浅克隆 |
g:plug_window | -tabnew | 打开插件窗口的命令 |
g:plug_pwindow | vertical rightbelow new | 在PlugDiff 中打开预览窗口的命令 |
g:plug_url_format | https://git::@github.com/%s.git | printf 格式构建repo URL(仅适用于后续Plug 命令) |
D
- PlugDiff
S
- PlugStatus
R
- 重试失败的更新或安装任务U
- 更新所选范围内的插件q
- 中止正在运行的任务或关闭窗口:PlugStatus
L
- 加载插件:PlugDiff
X
- 恢复更新有些插件在安装或更新后需要额外的步骤。在这种情况下,请使用do
选项来描述要执行的任务。
Plug ' Shougo/vimproc.vim ' , { ' do ' : ' make ' }
Plug ' ycm-core/YouCompleteMe ' , { ' do ' : ' ./install.py ' }
如果该值以:
开头,它将被识别为 Vim 命令。
Plug ' fatih/vim-go ' , { ' do ' : ' :GoInstallBinaries ' }
要调用 Vim 函数,您可以传递 lambda 表达式,如下所示:
Plug ' junegunn/fzf ' , { ' do ' : { - > fzf#install () } }
如果您需要更多控制,可以传递对采用字典参数的 Vim 函数的引用。
function ! BuildYCM (info)
" info is a dictionary with 3 fields
" - name: name of the plugin
" - status: 'installed', 'updated', or 'unchanged'
" - force: set on PlugInstall! or PlugUpdate!
if a: info .status == ' installed ' || a: info .force
! ./install. py
endif
endfunction
Plug ' ycm-core/YouCompleteMe ' , { ' do ' : function ( ' BuildYCM ' ) }
更新后挂钩在插件的目录内执行,并且仅在存储库更改时运行,但您可以使用命令的 bang-version 强制它无条件运行: PlugInstall!
和PlugUpdate!
。
提示
当您内联编写do
选项时,请确保转义 BAR 和双引号,因为它们会被错误地识别为命令分隔符或尾随注释的开头。
Plug ' junegunn/fzf ' , { ' do ' : ' yes | ./install ' }
但是,如果您使用变量(或任何 Vim 脚本表达式)提取内联规范,则可以避免转义,如下所示:
let g: fzf_install = ' yes | ./install '
Plug ' junegunn/fzf ' , { ' do ' : g: fzf_install }
PlugInstall!
和PlugUpdate!
安装程序在安装/更新插件时执行以下步骤:
git clone
或git fetch
从其来源git merge
远程分支带有!
命令后缀确保所有步骤无条件运行。
" NERD tree will be loaded on the first invocation of NERDTreeToggle command
Plug ' preservim/nerdtree ' , { ' on ' : ' NERDTreeToggle ' }
" Multiple commands
Plug ' junegunn/vim-github-dashboard ' , { ' on ' : [ ' GHDashboard ' , ' GHActivity ' ] }
" Loaded when clojure file is opened
Plug ' tpope/vim-fireplace ' , { ' for ' : ' clojure ' }
" Multiple file types
Plug ' kovisoft/paredit ' , { ' for ' : [ ' clojure ' , ' scheme ' ] }
" On-demand loading on both conditions
Plug ' junegunn/vader.vim ' , { ' on ' : ' Vader ' , ' for ' : ' vader ' }
" Code to execute when the plugin is lazily loaded on demand
Plug ' junegunn/goyo.vim ' , { ' for ' : ' markdown ' }
autocmd ! User goyo. vim echom ' Goyo is now loaded! '
笔记
你可能不需要。
正确实现的 Vim 插件应该已经延迟加载,无需插件管理器的任何帮助( :help autoload
)。因此,很少有情况下这些选项实际上有意义。使插件加载速度更快是插件开发人员的责任,而不是用户的责任。如果您发现某个插件加载时间过长,请考虑在该插件的问题跟踪器上提出问题。
让我给你一个观点。在现代计算机上,加载插件所需的时间通常小于 2 或 3 毫秒。因此,除非您使用大量插件,否则节省的时间不太可能超过 50 毫秒。如果您花了一个小时仔细设置选项以减少 50 毫秒,那么您将需要启动 Vim 72,000 次才能达到收支平衡。您应该问自己这是否是您的时间投资。
确保您通过使用--startuptime
缩短 Vim 的启动时间来解决正确的问题。
vim --startuptime /tmp/log
按需加载只能作为最后的手段。它基本上是一种 hacky 解决方法,并不总是保证有效。
提示
您可以将空列表传递给on
或for
选项以禁用插件的加载。您可以使用plug#load(NAMES...)
函数手动加载插件。
请参阅 https://github.com/junegunn/vim-plug/wiki/tips#loading-plugins-manually
麻省理工学院