My minimal .vimrc config

Cláudio Ribeiro
HackerNoon.com
4 min readApr 11, 2019

--

Over the last couple of weeks, I’ve been tasked with building and configuring countless virtual machines and coding environments for a couple of different projects we have right now.

It has been a great opportunity to get some sysadmin experience on my hands, but also to have an understanding of what tools and configurations I need to work on bare-bones Linux environments.

I love Vim and I work with it every day, but in this case I was installing vanilla Vim on these machines and using them to configure machines and do some actual coding on them. That gave me the idea for this article.

What configurations do I really need when using Vim?

On a daily basis, I use my carefully crafted .vimrc file. This file has everything I think I need to perform my work competently and is in constant flux. Always evolving to a better version of itself.

When installing Vim on a new machine, where I only need to perform some very light work, it didn’t make sense to get all my configurations. Doing that would be overkill. But there are a couple of configurations that not only made sense, but they also made my life easier and my experience better.

So without any further ado, I present to you

My minimal .vimrc configurations

Configuring Vim like a football team!
syntax enable
set tabstop=2
set number
set hlsearch
set incsearch
let g:netrw_liststyle = 3

First thing first, no set nocompatible. I use actually use this line on my bigger configuration file and I mention it in my book, but reality compatible is redundant if Vim finds a vimrc or gvmrc file compatible is turned off automatically.

The next two lines

syntax enable
set tabstop=2

I use mainly for code. syntax enable switches on syntax highlighting. Keywords in different programming languages will appear in different colors, making the code more readable. And set tabstop=2 will make tabs be 2 spaces wide. This number may vary and I may change it in real time to 4 depending on what programming language I’m working with. Tabs and spaces might be a little bit difficult to configure in Vim and because of that I should be using the bigger, much more complicated version of this line set tabstop=2 expandtab shiftwidth=2 smarttab.

set number is a no brainer, and a really useful tool to have. It simply shows the line numbers in the left. This way I can always easily know in which line I am and if I need to jump to a line using :25 or 7G I always know the line number to jump to.

set hlsearch and set incsearch are not what I call essentials, but they are nice to have. Configuration files sometimes are big and having both incremental search and search highlighting make it much easier to search for particular text bits.

The last line let g:netrw_liststyle = 3 is also a nice to have. Since having a file explorer can be a lot of times a life saver I sometimes use netrw. netrw is a file explorer plugin that comes bundled with Vim. So no need to install. What that line does is switching from the default folder view to a tree view. Having a tree view can give a much more detailed view of the project and that’s why I like to use.

Netrw in tree view mode

Some people like to take out the netrw banner (with the let g:netrw_banner = 0 option) but I kind of like it and used the tips on it more than once.

As you can see I also like to use tabs on Vim. I think tabs, together with netrw and the rest of the configurations above are more than enough to perform most tasks I need to perform. Let’s call it my desert island setup!

The best thing about this setup is that it is small enough that if I need to use a machine in one shot I don’t even need to create a .vimrc file, I just set them for that particular session. They are easy enough to remember!

When I actually want to use a machine more than once than I usually just set these rules when provisioning them. This is how I’ve been doing on vagrant:

if [ ! -f ~vagrant/.vimrc ]; then
touch ~vagrant/.vimrc
chown vagrant.vagrant ~vagrant/.vimrc
fi
value=$(grep -c "set tabstop=2" ~vagrant/.vimrc)
if [ $value -eq 0 ]; then
echo 'set tabstop=2' >> ~vagrant/.vimrc
echo 'set number' >> ~vagrant/.vimrc
echo 'set hlsearch' >> ~vagrant/.vimrc
echo 'set incsearch' >> ~vagrant/.vimrc
echo 'let g:netrw_liststyle = 3' >> ~vagrant/.vimrc
echo 'syntax enable' >> ~vagrant/.vimrc
fi

Conclusion

As programmers, using the right tools for the job is essential. But sometimes we might need to improvise, and that’s where having some knowledge of older tools and the ability to adapt can shine.

I’ll still use my main configuration file on a daily basis but I will not hesitate to change into minimal mode if I need to, it’s all a matter of adaptability, and as a programmer, we all need a bit of it.

Want to learn more about Vim? Want to learn how to use it as an IDE? Check out my new book An IDE Called Vim. It has everything from basic Vim usage to file finding, auto-completion, file manager and more.

--

--

Cláudio Ribeiro
HackerNoon.com

Software developer, writer and traveler from Portugal. Author of the books "An IDE Called Vim" and “Talk Vi(m)”.