Resource | Get rid of your Vim plugin manager

Get rid of your Vim plugin manager

Get rid of your Vim plugin manager

With the advent of Vim 8.0, there is now a native way to add plugins (now called packages), so you can get rid of your Vundle/Pathogen/<insert flavour here> package manager at long last.

I’ve been a happy user of Vundle for a number of years now, but the chance to simplify my configuration is always welcome.

If you’ve used Pathogen before, you will find Vim 8's native package management intuitive.

Simply place your package in a directory path like so:

~/.vim/pack/<package group>/start/<your package>

What is that start folder? I’m glad you asked… There are two possible folders you can have at that tier.

  1. The start folder contains packages that are loaded when Vim starts up.

  2. The opt folder contains “optional” package that are not loaded, but can be optionally loaded using :packadd packagename inside Vim.

But I miss Vundle…

If managing your packages using git submodules doesn’t sound fun (and it’s not, in my opinion) with a few lines of bash we can get a script that will install or update your packages. Just like Vundle but faster!

I always find an example easiest, so check out the below. The two methods at the top are the entire package manager install and update functionality!

On my machine, this file lives at: ~/.vim/pack/install.sh and running it updates existing packages and installs new ones. It is very fast! Adding a new package is a single line in this file, so in my mind, I’ve lost none of Vundle’s convenience.

#!/usr/bin/env bash

# Create new folder in ~/.vim/pack that contains a start folder and cd into it.
#
# Arguments:
#   package_group, a string folder name to create and change into.
#
# Examples:
#   set_group syntax-highlighting
#
function set_group () {
  package_group=$1
  path="$HOME/.vim/pack/$package_group/start"
  mkdir -p "$path"
  cd "$path" || exit
}

# Clone or update a git repo in the current directory.
#
# Arguments:
#   repo_url, a URL to the git repo.
#
# Examples:
#   package https://github.com/tpope/vim-endwise.git
#
function package () {
  repo_url=$1
  expected_repo=$(basename "$repo_url" .git)
  if [ -d "$expected_repo" ]; then
    cd "$expected_repo" || exit
    result=$(git pull --force)
    echo "$expected_repo: $result"
  else
    echo "$expected_repo: Installing..."
    git clone -q "$repo_url"
  fi
}

(
set_group ruby
package https://github.com/tpope/vim-rails.git &
package https://github.com/tpope/vim-rake.git &
package https://github.com/tpope/vim-bundler.git &
package https://github.com/tpope/vim-endwise.git &
wait
) &

(
set_group syntax
package https://github.com/kchmck/vim-coffee-script.git &
package https://github.com/tpope/vim-markdown.git &
package https://github.com/ap/vim-css-color.git &
wait
) &

(
set_group colorschemes
package https://github.com/altercation/vim-colors-solarized.git &
wait
) &

wait

There is a little bit of bash that may be unfamiliar:

  • ( &lt;set_group and package invocations&gt; ) & This starts a new subshell, so we can fetch all these packages with haste!

  • wait the magic keyword that tells bash to wait until all subshells have finished before continuing. Bash will only wait for subshells that are a direct child of the current process, hence why we need this call in each of our subshells to wait for each package call to finish before proceeding.

Well, I hope this inspires you to direct your package manager and move to a more native Vim experience! Reducing dependancies always feels good.

Message sent
Message could not be sent
|