Version Control your Vim Settings

October 24, 2021

I’ve used Vim as my main text editor since 2019. I love having my entire workflow in the terminal. Vim is highly configurable, I feel like I have full control of its UI, and behavior.

Here’s a screenshot from my Vim setup showing a React component from this blog:

Version controlling my Vim Config

A few months ago, I started version controlling my Vim settings and plugins. Adding version control allows me to experiment without worrying I’ll break anything. I became more comfortable tinkering with it and saw an improvement in my productivity.

If I’m having a problem with my settings, I can ask the Vim community and link to my Vim settings on GitHub.

Easy syncing between machines

I have a couple machines and virtual machines where I use Vim. So I have the need to sync Vim plugins and settings between machines.

By version controlling everything, I can setup a new machine with

cd
git clone https://github.com/hydrospanner/dotvim.git .vim
echo "runtime vimrc" > .vimrc

When Vim is opened, Plug, a Plugin manager included in my dotvim repo, will automatically install any missing plugins.

Pathogen vs Plug

Initially, I used Pathogen for Plugin management. It works by picking up plugins from repos cloned to ~/.vim/bundle/. It works great in a single machine, but syncing those plugins gets interesting. To track those Plugins in my dotvim repo, I could add those plugin repos as git submodules, and pull in changes with:

git pull
git submodule init
git submodule update

However, installing and updating vim packages in this way is really something Plug is designed for. Instead of tracking the plugins in a .gitmodules file, Plug allows me to list them in the vimrc config.

call plug#begin()
Plug 'tpope/vim-sensible'
call plug#end()

Neovim

I’ve also been using Neovim lately. There is a GitHub CoPilot plugin available for Neovim that’s not (yet) compatible with Vim.

Neovim has documentation on extending Vim’s config for Neovim. Adding this to Neovim’s init.vim config file gives me all my Vim configurations in Neovim.

set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
source ~/.vimrc

Then add Neovim specific configuration below that.

call plug#begin()
Plug 'github/copilot.vim'
call plug#end()

Note that the Plugs in the Vim config have to be installed from Vim, not Neovim.


Profile picture

Written by  John Tucker

having fun with data