A Better Way to Organize Your .vimrc

Published:
May 9, 2020

Vim is a powerful customizable editor. Configuration is stored in custom text files often found in a Unix home directory (ie ~/.vimrc). This vimrc file can get to be rather large the longer one uses vim.

Break the file into pieces

The number of files you use is infinite but it works best to keep things simple and organized. I use five files: plugin loader, general settings, leader key settings, custom functions, and plugin specific settings. Source each of these in your main vimrc. The $HOME/.vim/init directory is not used by vim so I keep my files there. (You can use the $HOME/.vim/autoload/ directory bit I have trouble with it)

Plugin loading

Modern vim has many ways to load plugins. VimPlug, Vundle, and NeoBundle use a list of plugins in a vimrc file to install plugins or packages. Create a single file that has the commands for the plugin manager. I use VimPlug.

Leader key settings

In the $HOME/.vim/init/leader.vimrc file I keep all my leader key shortcuts and settings. The order doesn’t matter so functions and plugin settings can be set even before they exist (functions.vimrc loads after)