vim-plug

The newest and the brightest in plugin management is vim-plug, a lightweight plugin that makes it easy to deal with a multitude of plugins. The plugin is available on GitHub at: https://github.com/junegunn/vim-plug (it has a rather friendly README file, but I've captured the gist of it in this section if you're feeling lazy).

There are some neat things about this plugin:

  • It's lightweight and fits in a single file, allowing for some straightforward installation options
  • It supports parallel plugin load (if Vim is compiled with Python or Ruby enabled, which is true for all modern Vim setups)
  • It supports the lazy loading of most plugins, only invoking plugins for a particular command or a file type
In the previous chapter, you manually installed the plugins. This section provides a much better plugin experience, and you'll want to delete the plugins you downloaded manually. In order to do that, remove the manually added plugin directory (rm -rf $HOME/.vim/pack in Linux and rmdir /s %USERPROFILE%vimfilespack in Windows).

Installing vim-plug is straightforward:

  1. Fetch the plugin file from https://raw.github.com/junegunn/vim-plug/master/plug.vim.
  2. Save the file as $HOME/.vim/autoload/plug.vim.
    To fetch a single file from GitHub, you can use curl or wget on Linux or macOS, or just open the link in the browser, right-click, and choose Save as.... For instance, you could run the following command to fetch the file in Unix:

    $ curl -fLo ~/.vim/autoload/plug.vim --create-dirs   https://raw.github.com/junegunn/vim-plug/master/plug.vim
  3. Update your .vimrc file to include vim-plug initializers:
    " Manage plugins with vim-plug.
    call plug#begin()
    call plug#end()
  4. Add some plugins between these two lines, using the last parts of the URL in GitHub (in <username>/<repository> format, for example scrooloose/nerdtree instead of https://github.com/scrooloose/nerdtree) to identify the plugins:
    " Manage plugins with vim-plug.
    call plug#begin()

    Plug 'scrooloose/nerdtree'
    Plug 'tpope/vim-vinegar'
    Plug 'ctrlpvim/ctrlp.vim'
    Plug 'mileszs/ack.vim'
    Plug 'easymotion/vim-easymotion'

    call plug#end()
  5. Save your .vimrc file and reload it (:w | source $MYVIMRC) or restart Vim to apply the changes. Execute :PlugInstall to install the plugins.

This will download the aforementioned plugins from GitHub:

There are two main commands you will use with vim-plug:

  • :PlugUpdate will update all of the plugins you have installed.
  • :PlugClean will delete the plugins you removed from your .vimrc file. If you don't run :PlugClean, the plugins you deactivated (by either commenting out or removing the relevant Plug ... line in your .vimrc file) will stay on your system.
Running :PlugUpdate updates every plugin vim-plug manages besides itself. If you want to update vim-plug, you need to run :PlugUpgrade and reload your .vimrc file by either running :source $MYVIMRC or restarting Vim. 

Lazy plugin loading is a useful tool to prevent plugins from slowing down Vim. The Plug directive supports optional parameters. For instance, if you wanted to load NERDTree when the :NERDTreeToggle command is called, you could use the on parameter:

Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }

If you wanted to only load a plugin for a particular file type, you could use the for parameter:

Plug 'junegunn/goyo.vim', { 'for': 'markdown' }
Due to the way vim-plug is installed, its help pages are not available by default. If you'd like to be able to call :help vim-plug, add Plug 'junegunn/vim-plug' to a list of installed plugins and run :PlugInstall.

You can find the list of supported parameters in vim-plug's README file on GitHub at: https://github.com/junegunn/vim-plug.

If you only work on Linux or Mac machines (and Cygwin), you can add a following piece to your .vimrc file to install vim-plug whenever you transport your .vimrc file to a new machine:

 " Install vim-plug if it's not already installed.
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
https://raw.github.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif

This will install vim-plug (and all the plugins you have listed) next time you open Vim.

You can see a slightly longer solution that works for both Windows and Unix on my blog: https://www.rosipov.com/blog/cross-platform-vim-plug-setup.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.212.145