Automatic Vim PlugUpdate
This post was inspired by this Reddit thread.
I use vim-plug to handle my vim
plugins and I want to keep my plugins up-to-date. Ideally, this would be done
automatically but I don’t want to suddenly have a broken vim setup. Luckily,
vim-plug
comes with a snapshot feature.
I save the following as ~/bin/vimplug_update
.
#! /usr/bin/env bash
vim_cmd="nvim"
BACKUP_DIR="$HOME/.vimplug_snapshots"
BACKUP_FILE="$BACKUP_DIR/snapshot_$(date +"%Y-%m-%d-%H%M%S").vim"
mkdir -p "$BACKUP_DIR"
$vim_cmd -c "PlugSnapshot $BACKUP_FILE" +qa
$vim_cmd +PlugUpdate +qa
Then I set a daily cron job by running crontab -e
and writing
@daily ~/bin/vimplug_update
. If I ever have to restore my settings, I run
vim -S snapshot_2019-08-05-085852.vim