My Not So Fancy .vimrc

Sometime in the early 1990s, for reasons I can't remember, I made the switch from pico to vim and never looked back. Since that time I've been slowly tweaking my config, occasionally adding a feature here and there, and always carrying my files along from one computer to another. My config is still mostly stock, unlike some friends who read the O'Reilly book and somehow managed to create a terminal version of Visual Studio. Every now and then I'll be working on a project and decide to look for a small boost. Something like syntax highlighting for LaTeX or puppet-lint for live syntax validation on Puppet manifests.

Every now and then I'll have someone come along who starts getting into vim. I've been using vim for so long that it's a part of me so I always feel a little thrill when someone new rediscovers something so old. I got this thrill just a few weeks ago when one of my Tweeples made the jump completely unexpectedly. Unlike GUI based applications the full power of something like vim is hard to wrap your head around. It's all bound up in exceptionally dense and esoteric documentation that can require an large amounts of organic experience to decode.

Knowing this I like to make it easy for people. I try to dole out tips and tricks as they use it so as not to become overwhelming. Which leads me to this post. Hoping it helps somebody scroll down a bit and find the .vimrc that I've been using all this time. Unlike what I did with my screenrc the .vimrc is much too large to chunk and describe in detail. With any luck the comments are sufficient to describe most of the settings.

Probably the most non-obvious portion is the first bit referring to Pathogen. Pathogen is a vim script that acts like a package manager for other vim scripts. Using the infect method it allows us to import all of the scripts we've installed in ~/.vim/bundle in one go. Specifically, I'm loading:

I find the most useful to be Syntastic. Whenever a file is written out it is syntax checked based on the Syntastic plugin and any stylistic deviations or syntax warnings and errors are indicated in a sidebar.

Setting it all up is pretty easy. Just follow the instructions on installing Pathogen and drop the following in your ~/.vimrc.

" Setup the environment for Syntastic syntax checking
call pathogen#infect('bundle/{}')

" Enable syntax highlighting
syntax on

" Show text description of code warnings and Syntastic notices in status line
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
 
filetype plugin on
filetype indent on

" Set up some settings for vim-latex
let g:tex_flavor='latex'
" Disable all that folding nonsense
let Tex_FoldedSections=""
let Tex_FoldedEnvironments=""
let Tex_FoldedMisc=""

" Set up the Solarized colorscheme
set background=dark
let g:solarized_visibility = "high"
let g:solarized_contrast = "high"
let g:solarized_termcolors = 256
let g:solarized_termtrans = 1
colorscheme solarized

set modeline

" Always assume paste mode
set paste

" Enable Markdown formatting
augroup mkd
    autocmd BufRead *.mkd  set ai formatoptions=tcroqn2 comments=n:>
augroup END

" Disable autoindenting
set noai

" have command-line completion <Tab> (for filenames, help topics, option names)
" first list the available options and complete the longest common part, then
" have further <Tab>s cycle through the possibilities:
set wildmode=list:longest,full

" Turn the mouse off for all modes, graphical and console
set mouse=

" When entering a tab with this on, spaces are entered instead (at 4 characters).
" To enter a real tab, use  CTRL-V TAB.
set expandtab
set tabstop=4
set shiftwidth=4

" make searches case-insensitive, unless they contain upper-case letters:
set ignorecase
set smartcase

" show the `best match so far' as search strings are typed:
set incsearch

" show cursor line and column in the status line
set ruler

" show matching brackets
set showmatch

" display the current mode and partially-typed commands in the status line:
set showmode
set showcmd

" Allows full backspacing, including over insertion points and line breaks
set bs=2

" Required to be able to use keypad keys and map missed escape sequences
set esckeys

" Disable vi compatability
set nocompatible

" enable filetype detection:
filetype on

" Syntax highlighting for iCal ics files
autocmd! BufRead,BufNewFile *.ics setfiletype icalendar

" for C-like programming, have automatic indentation:
autocmd FileType c,cpp,slang set cindent cinkeys cino=1s

" for actual C (not C++) programming where comments have explicit end
" characters, if starting a new line in the middle of a comment automatically
" insert the comment leader characters:
autocmd FileType c set formatoptions+=ro

" for CSS, also have things in braces indented:
autocmd FileType css set smartindent

" for HTML, generally format text, but if a long line has been created leave it
" alone when editing:
autocmd FileType html set formatoptions+=tl

" for both CSS and HTML, use genuine tab characters for indentation, to make
" files a few bytes smaller:
autocmd FileType html,css set noexpandtab tabstop=4

" in makefiles, don't expand tabs to spaces, since actual tab characters are
" needed, and have indentation at 8 chars to be sure that all indents are tabs
" (despite the mappings later):
autocmd FileType make set noexpandtab shiftwidth=8