How do I install a plugin in Vim?
Does it matter:
- Whether I use vi or Vim?
- Whether I use gVim?
- Which version of Vim I'm using?
- What my OS is?
To install a plugin, we need to know what form it comes in. It can be:
.vim
fileplugin/*
, syntax/*
, etc.) (What makes a plugin Vundle compatible and are other plugin managers interchangeable?)A single .vim
file is supposed to be placed in the .vim/plugin
directory.
A Vimball file can be installed by opening it in Vim and running :source %
.
A set of files in the standard directory layout can be installed either by copying them to .vim
, or using a plugin package manager.
Plugins may depend on certain features. Therefore:
For most plugins, though, it may not matter.
vi
on any modern box will probably just launch vim
with some features turned off. I doubt many people have access to actual Vi these days.
I like to use the vim-plug plugin manager.
The problem with manually installing a plugin is that it's rather difficult to remove a plugin; you often have several different files in different directories, you have to manually find them & remove them.
Upgrading problems is similarly difficult: What if autoload/old-name.vim
gets
renamed to autoload/new-name.vim
? You now have both an old and new version
of a plugin.
vim-plug
solves this by storing each plugin in it's own directory; it also
includes command to easily install/remove a plugin, so you don't have to muck
about with unzipping plugins and the like.
A key advantage of vim-plug over Pathogen is that vim-plug allows you to install and remove plugins more easily. All that Pathogen does is allow each plugin to be in a separate contained directory.
vim-plug relies on git; for MS Windows, you want msysgit.
You can define plugins in your vimrc like so:
call plug#begin('~/.vim/plugged')
" For MS Windows, this is probably better:
"call plug#begin('~/vimfiles/plugged')
Plug 'embear/vim-localvimrc'
Plug 'kchmck/vim-coffee-script'
" ... etc
call plug#end()
Then restart Vim, and then install plugins with:
:PlugInstall
This will put the plugins in ~/.vim/plugged
or $HOME\vimfiles\plugged
for MS
Windows.
You can add
this snippet from the FAQ to
your vimrc file before the plug#begin()
call:
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall
endif
Note you need curl
for this to work. This is almost always available on Linux and OSX, but not on MS Windows; so this trick won't work there...
To remove a plugin, remove it from the vimrc file and run:
:PlugClean
Note that vim-plug doesn't support installing scripts from the Vim scripts website, but those scripts are mirrored on GitHub, so there's no need to do so.
There are also some additional advantages to this such as easier updating of
plugin, and on-demand loading for better performance. You can also easily copy
your vimrc to another computer, run :PlugInstall
, and have all your plugins.
Note there are more plugin managers; I happen to use vim-plug
.
See also: What is the difference between the vim package managers?
Version 8 introduces a new packages mechanism that largely replaces the need for existing plugin managers (pathogen, vim-plug, vundle, etc.) at the time of writing (2017).
From the documentation:
A Vim package is a directory that contains one or more plugins
A package directory contains two sub-directories:
start/
- contains plugins that will be automatically loadedopt/
- contains plugins that are loaded on demand with :packadd
It may seem a bit complicated, but in practice all you have to do is add your plugin here:
↓ package name
~/ .vim / pack / bundle / start / some-plugin
↑ packages dir ↑ plugin dir
On Windows: use ~\vimfiles\pack\
instead of ~/.vim/pack/
By convention, we've used the package name "bundle" as the directory that will contain all our plugins. You can use any name you want, and you can even put your plugins in separate package directories if you really want to.
mkdir -p ~/.vim/pack/bundle/start
cd ~/.vim/pack/bundle/start
git clone https://github.com/tpope/vim-sensible.git
On Windows: use ~\vimfiles\pack\
instead of ~/.vim/pack/
Next time you start Vim, the plugin will load automatically.
.vim
is under version control, it might be better to install plugins with git's submodules; see shapeshed.com/vim-packages/#adding-a-package.
Commented
Feb 11, 2018 at 22:26
bundle/
subdirectory as "package name"? Isn't it a single directory for all packages? 2. Some plugins have two vim files, e.g. autoload/foo.vim
and plugin/foo.vim
. Do I just keep their internal structure within a ~/.vim/bundle/start/foo
subdir?
Commented
May 1, 2023 at 18:08
Pathogen is a runtime path manager, which loads plugins within Vim. It makes plugin installation simple; here's how it works:
note: If you're using Windows, replace ~/.vim
with $HOME\vimfiles
.
Copy pathogen.vim
to ~/.vim/autoload/pathogen.vim
.
Create the ~/.vim/bundle
directory, if it does not exist already.
Add the following line to the very beginning of your .vimrc
:
execute pathogen#infect()
You're done! When you want to add a plugin, simply copy the entire plugin's directory to ~/.vim/bundle
, or git clone
it there. For example:
cd ~/.vim/bundle
git clone https://github.com/tpope/vim-surround
* Caveat: If your plugin comes in the form of a .vim
file, it won't work with Pathogen. Copy it to ~/.vim/plugin
instead (you may have to create this directory if it doesn't exist).
git submodule add
(instead of git clone
) if your vim configuration is already part of your own git project.
Commented
Feb 11, 2015 at 5:53
runtimepath
option and that's all. It doesn't deal with updating,adding,retrieving,removing plugins at all.
Let us not forget the great & mighty Vundle!
Vundle is a complete plugin manager, with functionality for:
:PluginSearch
):PluginInstall
):PluginUpdate
):PluginClean
)As you can see, it's a lot like the vim-plug manager mentioned by Carpetsmoker. I don't know which one came first, but their APIs look very similar to me, as does the setup process.
.vimrc
, so when installing on a new server all you need is a Vundle installation + your .vimrc
to install everything. Plus you can comment out your plugins and 'clean' them, but be able to comment them back in months or years later when you've long forgotten their names.
Most likely, your plugin will be a single .vim file.
If this is the case, I searched the help and experimented and figured out the following. From within vim (command mode), type:
:set runtimepath
This will show you a series of directories.
Some of these directories will have a plugin
subdirectory. Putting any .vim file in one of these plugin
subdirectories will get it automatically loaded when you start vim from anywhere.
For me, on Ubuntu linux, I found that /usr/share/vim/vim74/plugin
worked well, to install for all users. You may need root permission to copy a file to here (prefix your cp
or mv
command with sudo
).
vim74
, which means that it is version specific, so upgrading to Vim 8.0, will loose that plugin. More upgrade-proof way would be to use /etc/vim/
for that (create it if not present, and add that path to runtimepath
if not available in /etc/vimrc
)
Most likely, your plugin will be a single .vim file
I disagree. A huge majority of plugins comes with a .txt
file containing the document and you need to generate the tags to get a functional doc. Also a lot of plugins comes with an autoload
directory. I think that using a plugin manager is a better solution than managing your runtimepath manually
/usr/share/vim/vimXX
is the stock runtime and is not the place for site configuration/plugins. Instead, site configs/plugins should be placed wherever $VIM
points on that system (see :h vimfiles
). Usually, this is /usr/share/vim
, which is the case for Ubuntu and holds symlinks to /etc/vim
. In general, /usr/local/
is the de-facto place for site configuration outside the package manager. Note that Neovim makes use of $XDG_(CONFIG|DATA)_DIRS
and site
directories, providing better out-of-the-box defaults for site configs.
Commented
Nov 30, 2018 at 4:46
Vire leverages the latest pack format to install plugins and supports Vim and Neovim. You don't need to know where anything goes. Just provide a vimrc and Vire will take care of the rest.