A Good Vimrc
DB
A Good Vimrc
Posted January 21th, 2014
How To Vimrc
There is just one rule you must follow when crafting your own .vimrc.
Don't put any lines in your vimrc that you don't understand.
There are tons of tutorials such as this one on the internet<br>that contain all kinds of awesome hacks to make your Vim better, but<br>the absolute worst way to make your environment better is to just copy<br>it wholesale from others.
Spending the time to actually learn what's going into the construction<br>of your editor is invaluable. In the same way that copying notes off a<br>projector by hand often leads to increased information retention,<br>adding features one by one to your vimrc aids in overall Vim<br>comprehension.
With that said, the rest of this article will be me explaining each and<br>every line in my current vimrc in its entirety with the hope that you<br>will find some tricks you haven't seen before. But! My vimrc is far<br>from perfect. I'm always looking for additions that would make my<br>environment better so if you think I missed something important please<br>let me know: @dougblackio.
I will break it up into logical sections.
Colors
Spaces And Tabs
UI Config
Searching
Folding
Custom Movements
Custom Leader
CtrlP Settings
Launch Config
Tmux Config
Autogroups
Backups
Custom Functions
Organization
Wrapping It Up
This article will almost certainly fall out of date with my vimrc in the<br>very near future. You can find the most up to date version of it<br>on github.
Colors
colorscheme badwolf " awesome colorscheme
Colors! Colorschemes are subjective, but I've currently settled on<br>badwolf by Steve Losh. I found solarized<br>incredibly complete, but a little too bland for my taste. I enjoy colors<br>that pop. I also spend a good deal of time with molokai<br>and still think it's a great scheme, but simply prefer badwolf at the<br>moment.
Moving on:
syntax enable " enable syntax processing
The comment should be enough to describe this one. I'll take this<br>moment to plug adding comments to most if not every line in your vimrc.<br>If you're anything like me that file is going to get pretty long, and<br>chances are you won't remember what every line does forever, so adding<br>comments will help Future You know what the hell is going on in there.
Also, many settings in Vim have both a long name and a short name. For<br>instance background is the same as bg. For future readability, I<br>strongly recommend using the long name.
Spaces & Tabs
The incantations you must throw into your vimrc to get tabs/spaces<br>working the way you want can be pretty confusing, so here's a quick<br>refresher.
set tabstop=4 " number of visual spaces per TAB
tabstop is the number of spaces a tab counts for. So, when Vim opens<br>a file and reads a character, it uses that many spaces to visually<br>show the .
set softtabstop=4 " number of spaces in tab when editing
softabstop is the number of spaces a tab counts for when editing. So<br>this value is the number of spaces that is inserted when you hit<br>and also the number of spaces that are removed when you<br>backspace.
set expandtab " tabs are spaces
expandtab turns s into spaces. That's it. So just<br>becomes a shortcut for "insert four spaces".
Taken together, these are great options for editing files in languages<br>that prefer spaces over tabs, since this ensures no s are actually<br>used. I spend most of my day in python and bash, where spaces are<br>the norm. I like it, since it means my source code looks the same on<br>every machine.
UI Config
These are options that change random visuals in Vim.
set number " show line numbers
Showing line numbers should need no justification.
set showcmd " show command in bottom bar
showcmd shows the last command entered in the very bottom<br>right of Vim. I have it set here but it's actually not shown<br>in my Vim since I use powerline plugin (which<br>we will get to later).
set cursorline " highlight current line
cursorline draws a horizontal highlight (or underline, depending on<br>your colorscheme) on the line your cursor is currently on. I've found<br>that this makes it easier to follow exactly what line you left off on<br>when you're switching back to a Vim session or switching between windows<br>in Vim.
filetype indent on " load filetype-specific indent files
This both turns on filetype detection and allows loading of language<br>specific indentation files based on that detection. For me, this<br>means the python indentation file that lives at<br>~/.vim/indent/python.vim gets loaded every time I open a *.py file.
set wildmenu " visual autocomplete for command menu
This is a pretty cool feature I didn't know Vim had. You know how Vim<br>automatically autocompletes things like filenames when you, for instance,<br>run :e ~/.vim? Well it will provide a graphical menu of all the<br>matches you can cycle through if you turn on wildmenu.
set lazyredraw " redraw only when we need to.
Vim loves to redraw the screen during things it probably doesn't need<br>to—like in the middle of macros. This tells Vim not to...