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
Throughout this post, we are going to be editing the
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
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.
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
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 Desktop Documents Downloads
.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
One last thing, if you ever want to edit your
.vimrc, no matter where you are in
your terminal, just type:
Turns on line numbers - a feature that is always necessary.
Allows for mouse control that is similar to other GUI editors.
Turns on syntax highlighting.
Highlights the line your cursor is on.
Sets tab length to four characters.
set tabstop=2 is also good if you indent a lot.
Autmoatically indents proper amount while inside a block of code.
Make all tabs use spaces, rather than the tab character.
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.
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
command Wq wq
When trying to save in vim, you normally must type
:w. Similarly, to save and quit, you
:wq. If you're as bad at typing as I am, then allowing for
:wq to become
:WQ (and or
will make those frustrating moments slightly less infuriating.
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