CREATIVE CHAOS   ▋ blog

From pathogen to native vim package loading via yadm

PUBLISHED ON 30/05/2019 — EDITED ON 11/12/2023 — SYSOPS

Intro

With version 8, our favourite editor Vim got support for native third-party package loading. For me this means I can ditch plugin helper Pathogen. The path we took was great but a bright future lies ahead with our seperate ways.

This little tutorial contains detailed steps to migrate your existing plugins from Pathogen to native package manager in Vim. On our way, we will adjust the settings of dot git repository, for which we use the magnificent yadm.

So we have:

  1. Vim 8 or greater.
  2. Pathogen set up.
  3. Some plugins loaded and pushed to yadm repo as submodules.

Removing pathogen and modules

Remove lines referencing Pathogen from your .vimrc:

execute pathogen#infect()
pathogen#helptags()

Remove the pathogen autoload folder:

rm -rf ~/.vim/autoload

Remove submodules from yadm

Check which submodules you have installed:

cat ~/.gitmodules
[submodule ".vim/bundle/nerdtree"]
    path = .vim/bundle/nerdtree
    url = git@github.com:scrooloose/nerdtree.git
[submodule ".vim/bundle/vim-airline"]
    path = .vim/bundle/vim-airline
    url = git@github.com:vim-airline/vim-airline.git
[submodule ".vim/bundle/vim-airline-themes"]
    path = .vim/bundle/vim-airline-themes
    url = git@github.com:vim-airline/vim-airline-themes.git
[submodule ".vim/bundle/ultisnips"]
    path = .vim/bundle/ultisnips
    url = git@github.com:SirVer/ultisnips.git
[submodule ".vim/bundle/vim-commentary"]
    path = .vim/bundle/vim-commentary
    url = git@github.com:tpope/vim-commentary.git
[submodule ".vim/bundle/vim-snippets"]
    path = .vim/bundle/vim-snippets
    url = git@github.com:honza/vim-snippets.git
[submodule ".vim/bundle/vim-surround"]
    path = .vim/bundle/vim-surround
    url = git@github.com:tpope/vim-surround.git
[submodule ".vim/bundle/undotree"]
    path = .vim/bundle/undotree
    url = https://github.com/mbbill/undotree.git
[submodule ".vim/bundle/supertab"]
    path = .vim/bundle/supertab
    url = git@github.com:ervandew/supertab.git
[submodule ".vim/bundle/vim-fugitive"]
    path = .vim/bundle/vim-fugitive
    url = git@github.com:tpope/vim-fugitive.git
[submodule ".vim/bundle/vimtex"]
    path = .vim/bundle/vimtex
    url = git@github.com:lervag/vimtex.git

Remove each module:

yadm rm ~/.vim/bundle/nerdtree
...

Prepare directory structure

Vim modules now live here:

mkdir ~/.vim/pack

Replace name of the subfolder (b4d) with arbitrary name/nickname:

mkdir ~/.vim/pack/b4d

Create a start folder, that will contain all of the plugins you want to autoload at start:

mkdir ~/.vim/pack/b4d/start

Create a opt folder for packages that you can later on load with :packadd name-of-the-package:

mkdir ~/.vim/pack/b4d/opt

Add new submodules to yadm

In my case I want all of them to autoload at vim startup, so I will stick them to the start subfolder:

yadm submodule add git@github.com:vim-airline/vim-airline.git .vim/pack/b4d/start/vim-airline
yadm submodule add git@github.com:vim-airline/vim-airline-themes.git .vim/pack/b4d/start/vim-airline-themes
yadm submodule add git@github.com:SirVer/ultisnips.git .vim/pack/b4d/start/ultisnips
yadm submodule add git@github.com:tpope/vim-commentary.git .vim/pack/b4d/start/vim-commentary
yadm submodule add git@github.com:honza/vim-snippets.git .vim/pack/b4d/start/vim-snippets
yadm submodule add git@github.com:tpope/vim-surround.git .vim/pack/b4d/start/vim-surround
yadm submodule add git@github.com:mbbill/undotree.git .vim/pack/b4d/start/undotree
yadm submodule add git@github.com:ervandew/supertab.git .vim/pack/b4d/start/supertab
yadm submodule add git@github.com:tpope/vim-fugitive.git .vim/pack/b4d/start/vim-fugitive
yadm submodule add git@github.com:lervag/vimtex.git .vim/pack/b4d/start/vimtex
yadm submodule add git@github.com:scrooloose/nerdtree.git .vim/pack/b4d/start/nerdtree

Commit your changes and push them to remote yadm repository.

yadm commit -m “Replacing vim pathogen with native vim packages.”

yadm push

Re-generating helptags

Native plugin managment has one drawback, helptags are not automatically re-generated.

You can update them by using:

:helptags ALL

Also, safely ignore the error:

E152: Cannot open /opt/local/share/vim/vim81/doc/tags for writing

Remote hosts

To update remote hosts that have yadm set up, we need to pull the changes and reinitialize the submodules.

yadm pull
yadm submodule update --init --recursive

In the future you can update all of the submodules by using:

yadm submodule update --recursive --remote

Automatic initialization of the submodules

Create a bootstrap file, that will execute every time you clone the repository. You can also run it by issuing yadm bootstrap command by hand.

vim ~/.yadm/bootstrap
#!/bin/bash

# Because Git submodule commands cannot operate without a work tree, they must
# be run from within $HOME (assuming this is the root of your dotfiles)
cd "$HOME"

echo "Init submodules"
yadm submodule update --recursive --init

Make it executable:

chmod +x ~/.yadm/bootstrap

This tip is from Bootstrap - official yadm documentation.

Post-pull hook to update submodules

vim ~/yadm/hooks/post_pull
#!/bin/bash

# Because Git submodule commands cannot operate without a work tree, they must
# be run from within $HOME (assuming this is the root of your dotfiles)
cd "$HOME"

echo "Update submodules"
yadm submodule update --recursive --remote

Make it executable:

chmod +x ~/yadm/hooks/post_pull

Idea for the last two tips comes from user TheLocehiliosan on Reddit.