May 24, 2021 Vim
Vim's plug-in configuration makes sense when you just add a file to customize your Vim experience, but it can be a mess when you want to use plug-ins written by someone else.
In the past, to use plug-ins written by someone else, you had to download all the files and place them correctly one by one.
You may also
zip
tar
to do placement work for you.
There are some obvious problems in this process:
utils.vim
or something more popular)? S
ometimes you can simply rename it off, but what if
autoload/
other name-related folder? I
f you change the file name, you change the plug-in.
It's not fun at all.
People sum up a series of hacks to make things easier, such as Vimball. F ortunately, we no longer have to put up with these dirty hacks. ated the famous Pathogen plug-in to make managing a large number of plug-ins easy and enjoyable, as long as the plug-in author is conscious of arranging the plug-in structure. (Translation: vundle is now recommended to replace Pathogen, which supports the use of git download plug-ins)
Let's take a look at how Pathogen works and what we need to do to make our plug-ins more compatible.
When Vim looks for files in a special folder, such as
syntax/
it doesn't just look up in a single place.
Like PATH on a Linux/Unix/BSD
PATH
Vim sets
runtimepath
find the files to load.
Create a
colors
desktop. C
reate a file called
mycolor.vim
folder (in this example you can leave it empty).
Open Vim and execute this command:
:color mycolor
Vim will display an error because it doesn't know how to look up your desktop. Now execute this command:
:set runtimepath=/Users/sjl/Desktop
Of course, you have to modify the path name according to your situation. Now try the color command again:
:color mycolor
This time Vim found
mycolor.vim
it will no longer report errors.
Since the file is empty, it doesn't actually do
anything, but
since it's no longer wrong, we're sure it's found.
The Pathogen plug-in automatically adds paths to your
runtimepath
Vim. A
ll
~/.vim/bundle/
be added to
runtimepath
one by one.
That's what vundle did.
This means
bundle/
include some or all of the standard Vim plug-in
colors/
syntax/
Vim can now load files from each folder, and each plug-in file is independent of its own folder.
It's much easier to update the plug-in. A
ll you need to do is remove the old plug-in folder and usher in a new version. I
f you manage the
~/.vim
folder through version control (which you should), you can use Mercurial's subbrepo or Git's submodule feature to check out the code base for each plug-in directly, and
hg pull; hg update
or
git pull origin master
to update.
We plan to have our users install the Potion plug-in we wrote through Pathogen. W hat we need to do: Put our files in the right folder in the plug-in's code base. It's as simple as that!
The code base for our plug-in looks like this when expanded:
potion/
README
LICENSE
doc/
potion.txt
ftdetect/
potion.vim
ftplugin/
potion.vim
syntax/
potion.vim
... etc ...
We place it on GitHub or Bitbucket so that users can simply clone it
bundle/
everything goes well!
If you haven't installed it yet, install it. (The original text is to install Pathogen, but it is not necessary)
Create a Mercury or Git code base for your plug-in,
potion
You can put it where you like it and link it to
~/.vim/bundle/potion/
just put it directly at
~/.vim/bindle/potion/
Create
README
and LICENSE files in the
LICENSE
base, and then comet.
Push to Bitbucket or GitHub.
Read
:help runtimepath
.