18 April 2017

Magit is an extremely helpful Emacs extension to do Git tasks from within the editor. Prefer Vim to Emacs, you say? Fear not: there is an ongoing effort to create a similar plugin for Vim, called Vimagit.

Since Vim has caught the package manager disease, the installation instructions can quickly lead you astray tough, so as a public service; here is how to install it for all users in your (Ubuntu) system:

pushd $(mktemp -d)

# install here
ADDONS=/var/lib/vim/addons

# download and unpack latest version from GitHub
wget -q -O - http://github.com/jreybert/vimagit/tarball/master | tar zx --strip-components=1

# install in system directory
for f in $(find autoload plugin syntax common -name '*.vim') $(find doc -name '*.txt'); do
  sudo install -o root -g root -m u=rwX,go=rX -D -t ${ADDONS}/$(dirname $f) $f
done

# update help tags
(cd ${ADDONS}; sudo vim -u NONE -c "helptags doc/" -c q)

# clean up temporary files
rm -rf "${DIRSTACK[0]}"
popd

# check that plugin is loaded
[ $(vim -c "scriptnames" -c q 2>/dev/null | grep -c ${ADDONS}/plugin/magit.vim) -gt 0 ]

Now you can add a line like this to your ~/.vimrc to invoke it with a keyboard shortcut:

:nmap <C-x>g :Magit<CR>

OK, maybe that was a little bit too Emacs-y…