How do I maintain my Vim settings

My first contact with the text editor Vim was when I’ve just started college, in a Math class almost 10 years ago. Before the class started, a classmate, Dirley, that I didn’t meet yet, was sitting in the front rows with his laptop open working on some project.

Black screen divided in half, at one side texts with coloured fonts and the other lines and more lines scrolling across the screen. Whenever Dirley pressed some keys, everything moved and changed. He was in the Matrix! If he offered me a red pill, I’d accept without thinking twice!

And this is how I got to know Vim. As soon as I started learning about it, I got impressed by how beloved that text editor was and the size of its community—millions of plugins, themes, shortcuts and settings. Suddenly, I was part of it. Countless hours spent trying to exit vim new plugins, changing settings, getting new colour schemes, and starting over again because it stopped working.

Until one day I decided to learn for real what I could and wanted to change inside Vim. Since then, for at least 6 years ago, I mostly use the setting structure, changing just a few things over the years.

In this blog post, I won’t talk about which setting or plugin you must use, but how to organize it for the long term use and how to not get lost while trying new things.

Divide and conquer

The .vimrc is the file that Vim searches for user configurations. In my case, I divided it into 4 different files, making the .vimrc just as an aggregator. The idea of this structure came from my dear friend Humberto, who taught me a lot about Vim.

" Vim Settings
source ~/.vim/config.vim

" Plugins I use
source ~/.vim/plugins.vim

" Plugin settings
source ~/.vim/plugin_config.vim

" Shortcuts
source ~/.vim/shortcuts.vim

Vim settings

Every configuration we can change on Vim, except for shortcuts, goes to config.vim file. As a guide to choosing what and how to configure the edit, I used a lot Vim’s official documentation, in particular the options section. You can read the documentation at the vimhelp.org website, but if you access it from inside Vim, here it goes some tips:

One of the configurations I like the most, is to be able to open a file on Vim with the cursor in the same place it was when I close the file for the last time:

au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif

Check out the rest of my setting at config.vim.

Plugins

I listed every plugin in the plugins.vim file and I installed them using vim-plug. Until version 8, released in 2016, Vim required a plugin, like vim-plug, to install other plugins. Since vim-plug always worked with me, I didn’t migrate to the native option.

The 3 plugins I like the most are:

Example of how to use vim-plug to install the 3 plugins above:

" Activate vim-plug
call plug#begin()

Plug 'scrooloose/nerdtree'
Plug 'kien/ctrlp.vim'
Plug 'airblade/vim-gitgutter'

" You can install any plugin directly from Github:
" Plug 'profile/plugin'

" All plugins must be listed between the `plug#begin()` and `plug#end()`
call plug#end()

Plugins settings

Each plugin has a set of configurations you can change, e.g. shortcuts to open ctrl.vim and NERDTree. At that time, I chose to break the plugin settings into a different file, plugin_config.vim. I’d do it differently today. Since I don’t use many plugins, a single file to install and configure them would be enough.

Shortcuts

The last time the shortcuts.vim file was modified was 5 years ago, when I reorganized the repository. I limited myself to just a few changes, since Vim’s shortcuts make you productive, despite being hard to learn. Besides that, not being creative on shortcuts helps you whenever you have to use Vim in a computer without your configurations, like when accessing a remote server or pairing with someone else computer.

The shortcut I use the most is jj, that I mapped to ESC key, so, when I type jj, Vim understand as the ESC key:

imap jj <esc>

Every file I talked about can be found on this repository. You can follow the README.me instructions to install them or you fork it and add your settings.

Meme Fork All The Things

Remember, to exit Vim: :q

o/