Doug Rudolph

Vimrc Starter Kit

Posted on April 11th, 2018

I can go on for quite awhile about how intricate vim settings can get, but when searching the internet about creating a bare-bones .vimrc, I couldn't find a single article. So here's a brief post to start off your .vimrc.

  1. Creating Your .vimrc
  2. First Set of Commands
  3. Example Raw .vimrc File

Creating Your .vimrc

Throughout this post, we are going to be editing the .vimrc file. Before we start editing files, we first have to understand what files we are going to be creating throughout this tutorial - as well as the purpose of each file. Lucky for us, the only file we are going to be editing is the .vimrc. The only purpose of the .vimrc is to store settings Important to quickly introduce what a .vimrc file is. To start, open your terminal and write touch ~/.vimrc - press enter when you're done. If you know what you're doing, you can skip to the next section, otherwise, keep reading.

The touch command we entered creates a .vimrc file in the home folder if one doesn't exist. The off chance is does exist, all touch does is update the date and time that file was last accessed.

Now when creating a file that contains a . in the beginning of its name, the . denotes that the file is designed to be hidden. Therefore searching for your .vimrc file is a little more complicated than just ls ~/. Instead, we must use ls -a ~/. The -a simply stands for all and will show all files in a folder - even those that are hidden.

Take a look at what happens when we run ls -a ~/

.vimrc                             Library
.zcompdump-DouglasRudolph-MBPr-5.3 Movies
.zsh-update                        Music
.zsh_history                       Pictures
.zshrc                             Public
Applications                       VirtualBox VMs

Our .vimrc shows up.

Now remember it's important for your .vimrc to be in the home directory in order for vim to recognize it - thats what ~/ stands for. (just another way to write home directory) You'll know if you're in your home directory when the command pwd returns /Users/your-usermame.

One last thing, if you ever want to edit your .vimrc, no matter where you are in your terminal, just type: vim ~/.vimrc.

First Set of Commands

Line Numbers: set number

Turns on line numbers - a feature that is always necessary.

Mouse Navigation: set mouse=a

Allows for mouse control that is similar to other GUI editors.

Syntax Highlighting: syntax on

Turns on syntax highlighting.

Set cursorline: set cursorline

Highlights the line your cursor is on.

Tab length: set tabstop=4

Sets tab length to four characters. set tabstop=2 is also good if you indent a lot.

Auto Indenting: set autoindent

Autmoatically indents proper amount while inside a block of code.

Tabs & Spaces: set expandtab

Make all tabs use spaces, rather than the tab character.

Line Measure: set colorcolumn 100

Adds a line measure at the 100th character mark. It's helpful to know when a line of code is getting too long.

Realtime Highlight search: set incrsearch set hlsearch

set incrseach will highlight code as you search for a phrase, but won't keep the phrase highlighted after you're done searching. Thus, using set hlsearch allows the search phrase to stay highlighted after you exit search mode. Turning on both settings creates for a normal feeling search.

Non-case Sensistive Commands: command Wq wq

When trying to save in vim, you normally must type :w. Similarly, to save and quit, you must type :wq. If you're as bad at typing as I am, then allowing for :w to become :W and :wq to become :WQ (and or :Wq) will make those frustrating moments slightly less infuriating.

Example Raw .vimrc File

Feel free to reuse this example .vimrc for your own use.

" Author: Your Name
" File: .vimrc

" turn on line numbers
set number

" turn on mouse
set mouse=a

" turn on syntax highlighting
syntax on

" highlight the line your cursor is on
set cursorline

" set tab length to 4
set tabstop=4

" autoindent inside code blocks
set autoindent

" make all tabs spaces
set expandtab

" line measure at character 100
set colorcolumn 100

" highlight search
set incsearch
set hlsearch

" non-case sensitive saving & quit commands
command WQ wq
command Wq wq
command W w
command Q q