vim-plug 配置安裝和配置

做個記錄

地址:

https://github.com/junegunn/vim-plug

安裝方式:

Installation

Download plug.vim and put it in the "autoload" directory.

Vim

Unix

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

You can automate the process by putting the command in your Vim configuration file as suggested here.

Windows (PowerShell)

md ~\vimfiles\autoload
$uri = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
(New-Object Net.WebClient).DownloadFile(
  $uri,
  $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(
    "~\vimfiles\autoload\plug.vim"
  )
)

Neovim

Unix

curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Windows (PowerShell)

md ~\AppData\Local\nvim\autoload
$uri = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
(New-Object Net.WebClient).DownloadFile(
  $uri,
  $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(
    "~\AppData\Local\nvim\autoload\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 ~/.config/nvim/init.vim for Neovim):

  1. Begin the section with call plug#begin()
  2. List the plugins with Plug commands
  3. call plug#end() to update &runtimepath and initialize plugin system
    • Automatically executes filetype plugin indent on and syntax enable. You can revert the settings after the call. e.g. filetype indent offsyntax off, etc.

Example

" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

" Make sure you use single quotes

" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'

" Any valid git URL is allowed
Plug 'https://github.com/junegunn/vim-github-dashboard.git'

" Multiple Plug commands can be written in a single line using | separators
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'

" On-demand loading
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

" Using a non-master branch
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }

" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }

" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }

" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }

" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'

" Initialize plugin system
call plug#end()

Reload .vimrc and :PlugInstall to install plugins.

Commands

CommandDescription
PlugInstall [name ...] [#threads]Install plugins
PlugUpdate [name ...] [#threads]Install or update plugins
PlugClean[!]Remove unused directories (bang version will clean without prompt)
PlugUpgradeUpgrade vim-plug itself
PlugStatusCheck the status of plugins
PlugDiffExamine changes from the previous update and the pending changes
PlugSnapshot[!] [output path]Generate script for restoring the current snapshot of the plugins

Plug options

OptionDescription
branch/tag/commitBranch/tag/commit of the repository to use
rtpSubdirectory that contains Vim plugin
dirCustom directory for the plugin
asUse different name for the plugin
doPost-update hook (string or funcref)
onOn-demand loading: Commands or <Plug>-mappings
forOn-demand loading: File types
frozenDo not update unless explicitly specified

Global options

FlagDefaultDescription
g:plug_threads16Default number of threads to use
g:plug_timeout60Time limit of each task in seconds (Ruby & Python)
g:plug_retries2Number of retries in case of timeout (Ruby & Python)
g:plug_shallow1Use shallow clone
g:plug_windowvertical topleft newCommand to open plug window
g:plug_pwindowabove 12newCommand to open preview window in PlugDiff
g:plug_url_formathttps://git::@github.com/%s.gitprintf format to build repo URL (Only applies to the subsequent Plug commands)

Keybindings

  • D - PlugDiff
  • S - PlugStatus
  • R - Retry failed update or installation tasks
  • U - Update plugins in the selected range
  • q - Close the window
  • :PlugStatus
    • L - Load plugin
  • :PlugDiff
    • X - Revert the update

Example: A small sensible Vim configuration

call plug#begin()
Plug 'tpope/vim-sensible'
call plug#end()

On-demand loading of plugins

" NERD tree will be loaded on the first invocation of NERDTreeToggle command
Plug 'scrooloose/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!'

for option is generally not needed as most plugins for specific file types usually don't have too much code in plugindirectory. 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 do option to describe the task to be performed.

Plug 'Shougo/vimproc.vim', { 'do': 'make' }
Plug 'Valloric/YouCompleteMe', { 'do': './install.py' }

If the value starts with :, it will be recognized as a Vim command.

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.

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 'Valloric/YouCompleteMe', { 'do': function('BuildYCM') }

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! andPlugUpdate!.

Make sure to escape BARs and double-quotes when you write do option inline as they are mistakenly recognized as command separator or the start of the trailing comment.

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:

let g:fzf_install = 'yes | ./install'
Plug 'junegunn/fzf', { 'do': g:fzf_install }

PlugInstall! and PlugUpdate!

The installer takes the following steps when installing/updating a plugin:

  1. git clone or git fetch from its origin
  2. Check out branch, tag, or commit and optionally git merge remote branch
  3. If the plugin was updated (or installed for the first time)
    1. Update submodules
    2. Execute post-update hooks

The commands with ! suffix ensure that all steps are run unconditionally.

Articles

 

### 回答1: vim-plug是一个用于安装和管理Vim插件的工具。通常,在线安装vim-plug是最常见的做法,因为它可以自动下载和安装插件。但是,有时候我们可能会遇到一些离线情况,无法连接到互联网。在这种情况下,我们可以使用离线安装方法来安装vim-plug。 离线安装vim-plug需要以下几个步骤: 1. 首先,你需要从vim-plug的官方网站(https://github.com/junegunn/vim-plug)下载vim-plug的代码,并将其保存在本地的某个目录中。 2. 在Vim配置文件(通常是~/.vimrc)中添加以下内容来启用vim-plug: ``` call plug#begin('~/.vim/plugged') " 插件安装相关配置 call plug#end() ``` 3. 接下来,需要在Vim中运行以下命令来安装vim-plug: ``` :source ~/.vimrc :PlugInstall ``` 4. 此时,vim-plug会尝试从互联网上下载插件,但由于离线状态,下载会失败。在失败的提示中,会显示每个插件应该存储的目录路径。 5. 打开你的离线机器的终端,将vim-plug下载的插件文件从其他可联网机器的Vim插件目录复制到相应的目录中。例如: ``` cp -r /path/to/online/machine/vim-plugins/* ~/.vim/plugged/ ``` 注意,其中`/path/to/online/machine/vim-plugins/`是你已在联网机器上安装vim-plug并下载了插件的目录。 6. 完成上述复制后,在离线机器的Vim中再次运行以下命令: ``` :source ~/.vimrc :PlugInstall ``` 这样,vim-plug会检测到已经存在插件文件,然后完成安装过程。 总之,vim-plug的离线安装并不复杂,只需要将插件文件从其他可联网机器复制到离线机器的插件目录中即可。 ### 回答2: 要在离线环境下安装vim-plug插件管理器,你需要先从官方源代码库或其他资源渠道下载最新版的vim-plug插件。 首先,在你能够连接到互联网的环境中,打开一个浏览器,并搜索“vim-plug官方网站”。找到vim-plug的官方网站后,浏览并查找下载链接。下载链接通常在网站的首页或者相关页面中。 下载vim-plug插件的压缩包后,将其复制到一个U盘或其他可移动介质上,然后将U盘或介质插入你需要离线安装vim-plug的电脑中。 接下来,在你想要安装vim-plug的电脑中打开终端或命令提示符。进入vim的插件目录,通常是`~/.vim`或`C:\Program Files\vim\vimfiles`,具体路径可能因操作系统和配置而有所不同。 现在,将U盘或者介质中的vim-plug压缩包解压到插件目录中。你可以使用`unzip`命令或者其他解压工具来完成。解压后你应该能够在插件目录中看到vim-plug的文件和文件夹。 最后,打开vim编辑器,在命令模式下输入`:source ~/.vim/plug.vim`(假设vim插件目录是`~/.vim`)来加载vim-plug插件。现在你就可以使用vim-plug来安装其他插件了。 请注意,vim-plug插件可能依赖于一些其他的库或软件包,这些库或软件包可能需要在离线环境中手动安装。你可以通过查阅vim-plug的文档或其他资源来获取更多关于依赖项的信息。 总结:要在离线环境中安装vim-plug,你需要先从官方网站下载vim-plug插件的压缩包,并将其解压到vim的插件目录中。然后在vim中加载vim-plug插件,即可开始使用它来安装其他插件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值