Find file
Fetching contributors…
Cannot retrieve contributors at this time
1121 lines (903 sloc) 29.8 KB

Viming With Buttars

Maintainer: Jeff Buttars
Git Hub Repo

To use this .vimrc copy it to :

  • On Linux, OS X, Unix and OS/2: ~/.vimrc
  • On Amiga: s:.vimrc
  • On MS-DOS and Win32: $VIM_vimrc
  • On OpenVMS: sys$login:.vimrc

Original Maintainer: Bram Moolenaar

Bram wrote/writes Vim, send money to his charity for Uganda. Find more info at

If your reading this as a README on GitHub you should know that this README is generted from the .vimrc file of this project using Vimdown

After each code block I will try to put some links to the appropriate vimdoc pages for the Vim features used in the section. This is a large .vimrc file and I have yet to tame it. So it's not in a great order, a work in progress.

.vimrc sections:


We deal with our bundles first thing because later sections rely on them being available.


Pathogen is a nice package format for Vim 'packages'.
Vundle is a great package manager for Pathogen bundles.

Call infect to get the bundle handling started.

call pathogen#infect()

Brief help on Bundle commands
:BundleList - list configured bundles :BundleInstall(!) - install(update) bundles :BundleSearch(!) foo - search(or refresh cache first) for foo :BundleClean(!) - confirm(or auto-approve) removal of unused

see :h vundle for more details or wiki for FAQ NOTE: comments after Bundle command are not allowed..

Vundle Configuration Add vundle to our runtime path (rtp) and start vundle

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

Bundles let Vundle manage Vundle required!

Bundle 'gmarik/vundle'

git-hub specific bundles:

Bundle 'vim-scripts/LustyExplorer'
   " Bundle 'garbas/vim-snipmate'
Bundle 'UltiSnips'
Bundle 'vim-scripts/tComment'
Bundle 'rygwdn/vim-conque'
   " Bundle 'kogakure/vim-sparkup'
Bundle 'ZenCoding.vim'

Other bundles

Bundle 'pep8'
Bundle 'a.vim'
Bundle 'vcscommand.vim'
Bundle 'python.vim'
Bundle 'vim-ipython'
Bundle ''
Bundle 'vim-indent-object'
Bundle 'histwin.vim'
Bundle 'Tabular'
Bundle 'ScrollColors'
Bundle 'LargeFile'
Bundle 'tlib'
Bundle 'Python-Syntax'

Bundle 'colorsupport.vim'


Lucius is a great 256 color theme with both light and dark schemes.
Hemisu looks nice, going to try it out for a while

Bundle 'Lucius'
Bundle 'noahfrederick/Hemisu'

The following are schemes I like, but I'm not using them right now.

    " Bundle 'eclm_wombat.vim'
    " Bundle 'wombat256.vim'
    " Bundle 'Wombat'
    " Bundle 'jellybeans.vim'
    " Bundle 'github-theme'

Vim Options

When started as "evim", evim.vim will already have done these settings, so we'll bail out in that scenario

if v:progname =~? "evim"

Use Vim settings, rather then Vi settings (much better!). This must be first, because it changes other options as a side effect.

set nocompatible " Don't be compatible with basic Vi

set backspace=indent,eol,start " allow backspacing over everything in insert mode

set nobackup " do not keep a backup file, use versions instead

set history=1000 " keep 1000 lines of command line history

Ruler and Statusline

I don't use the following ruler and statusline examples, I have a more advanced version of setting the status line in my hacks.vim

Examples of using set ruler and set statusline

  " set ruler    " show the cursor position all the time
  " Set up a custom status line. Like setting ruler, statusline overrides ruler, but we add the buffer number and filetype to the status:
  " set statusline=%<%y\ b%n\ %h%m%r%=%-14.(%l,%c%V%)\ %P
  " Set up a custom status line. Like setting ruler, statusline overrides ruler, but we add the buffer number and filetype to the status:
  " set statusline=%<%y\ b%n\ %h%m%r%=%-14.(%l,%c%V%)\ %P
  " or
  " set statusline=%<%y\ b%n\ %h%m%r%=%-14.(%l,%c%V%)\ %{&textwidth}\ %P

Set up some buffer and window behaviors

set switchbuf=useopen
set laststatus=2          " last window will always have a status line
set showcmd              " display incomplete commands

For Win32 GUI: you can remove 't' flag from 'guioptions' for no tearoff menu entries

    " let &[guioptions = substitute(&guioptions, "t", "", "g")

If we're running Vim 7.3 or newer, enable persistent undo and tell vim were to store the undo files.

if version >= 703
    set undofile
    set undodir=~/.vim/undos

In many terminal emulators the mouse works just fine, thus enable it.

if has('mouse')
  set mouse=a

Switch syntax highlighting on if the terminal supports colors or if we're runnig in a GUI. Also switch on highlighting of the last used search pattern.

if &t_Co > 2 || has("gui_running")
    syntax on
    set hlsearch

    "set guioptions-=m " Will remove menu bar from gvim
    set guioptions-=T " Remove toolbar from gvim

    " Set gvim font. I like the Inconsolata font.
    " You'll need to install, do it, it's very much worth it.
    " A great font, and it's 100% free.
    set guifont=Inconsolata\ Medium\ 10

I don't use the following, but some like it so I included for FYI purposes:

This line will make Vim set out tab characters, trailing whitespace and invisible spaces visually, and additionally use the # sign at the end of lines to mark lines that extend off-screen. For more info, see :h listchars

   " set list  
   " set listchars=tab:\|.,trail:.,extends:#,nbsp:.

We take for granted that we are connected to a fast terminal most of the time

set ttyfast
set laststatus=2 " keep the status line showing
set incsearch    " Enable incremental searching


We check if autocommands are enabled before we use them.

if has("autocmd")

   "In some files, like HTML and XML files, tabs are fine and showing them is
   "really annoying, you can disable them easily using the autocmd declaration:
   " autocmd filetype html,xml set listchars-=tab:>.

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text,txt setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END
    set autoindent      " always set autoindenting on
endif " has("autocmd")

*autoindent Convenient command to see the difference between the current buffer and the file it was loaded from, thus the changes you made. Only define it when not defined already.

  " if !exists(":DiffOrig")
  "    command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
  "    \ | wincmd p | diffthis
  " endif

I like to have my files automatically reloaded if they change on disk

set autoread

This allows us to save a file as root with the :w!! command, if we have sudo privileges, " when we're not currently useing vim as root

cmap w!! %!sudo tee > /dev/null %

Auto close the preview window after a short time of inactivity

autocmd CursorHold * if pumvisible() == 0|pclose|endif
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif

OmniCompletion settings

No much going on here for Omni Completion. In the past there were all sorts of nasty hacks for this section.
When c-y is used to select a completion, enter normal mode after it's inserted.

imap <c-y> <c-y><esc>
set completeopt=menuone,preview,longest

You can tweak what is searched and in what order for keyword completion. This .vimrc only uses the defaults for now. Here are some quick examples of setting it. (default: ".,w,b,u,t,i")

   "set complete=".,w,b,u,U,t,i,kspell,d,t"
   "set complete=".,w,b,u,t,i,kspell"


CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo, so that you can undo CTRL-U after inserting a line break.

inoremap <C-U> <C-G>u<C-U>

Map omnicomplete to Control-o while in insert mode.

   " For reasons I have yet to figure out this mapping is broken, 
   " so it's commented out for now.
   " imap <C-O> <C-X><C-O> 

Mapping for the a.vim plugin quickly switch between source and header files with when editing C files

autocmd FileType c imap <silent> <C-S> <ESC>:A<CR>
autocmd FileType c nmap <silent> <C-S> <ESC>:A<CR>

Enter will do a simple accept of the selection Moved this into delimitMate to get them to work together

function! CleverCR()
    if !pumvisible() 
        return "\<CR>"

    return "\<C-Y>"
inoremap <CR> <C-R>=CleverCR()<CR>

Use the F3 key to toggle line numbers between absolute and relative

function! ToggleRNU()
    if 0 == &rnu
        set relativenumber
        set number 
nmap <silent> <F3> <ESC>:call ToggleRNU()<CR>

The ';' ':' shortcut. For example, to save a file, you type :w normally, which means:

Press and hold Shift
Press ;
Release the Shift key
Press w
Press Return
This trick strips off steps 1 and 3 for each Vim command. It takes some times for your muscle memory to get used to this new ;w command, but once you use it, you don’t want to go back!

nnoremap ; :

If you like long lines with line wrapping enabled, this solves the problem that pressing down jumpes your cursor “over” the current line to the next line. It changes behaviour so that it jumps to the next row in the editor (much more natural):

nnoremap j gj
nnoremap k gk

Easier window navigation when you split up your buffers. Use J instead of CTRL-W j, etc.
Personally, this interferes with other shortcuts and I'm OK using the defaults, so I'll comment this out and leave it here in case someone reading this finds it useful.

   " nnoremap <C-j> <c-w>j
   " nnoremap <C-h> <c-w>h
   " nnoremap <C-k> <c-w>k
   " nnoremap <C-l> <c-w>l

We're extra friendly for Django and for SnipMate/UltiSnips, I want to use HTML snippets with my markdown wo we chain the filetypes

autocmd FileType python set ft=python.django        " For SnipMate
autocmd BufRead *.djml set ft=html.htmldjango   " For SnipMate
autocmd FileType mkd set ft=mkd.html

From an idea by Michael Naumann You press * or # to search for the current visual selection !! Really useful

function! VisualSearch(direction) range
  let l:saved_reg = @"
  execute "normal! vgvy"
  let l:pattern = escape(@", '\\/.*$^~[]')
  let l:pattern = substitute(l:pattern, "\n$", "", "")
  if a:direction == 'b'
    execute "normal ?" . l:pattern . "^M"
    execute "normal /" . l:pattern . "^M"
  let @/ = l:pattern
  let @" = l:saved_reg
vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>

End From an idea by Michael Naumann

More normal Vim tweaks. vertical: make a diff split vertical by default iwhite: ignore whitespace context: show 10 lines of context set diffopt=filler,vertical,iwhite,context:10

set diffopt=filler,vertical,context:15
let g:html_diff_one_file = 1

Use real tabs, 4 spaces I prefer to use realtabs, but, I'm overruled by spaces. Use this if you want real tabs.

set tabstop=4
set shiftwidth=4
set shiftround  " use multiple of shiftwidth when indenting with '<' and '>'
set smarttab

A gave in and use spaces instead of real tabs

set tabstop=4
set softtabstop=4
set shiftwidth=4
set textwidth=80
set smarttab
set shiftround  " use multiple of shiftwidth when indenting with '<' and '>'
set expandtab

Show matching braces

set showmatch 

Quick blink when a match is made

set mat=5

Keep our swap and backup files out of the way and in a central palce. set directory=~/.vim/swapback set backupdir=~/.vim/swapback Screw the swap file

set noswapfile

C opts Kernel style set cinoptions=:0,(0,u0,W1s I use the default, you should check out the help for cinoptions and tune it to match your prefered style. :h cinoptions

set cinoptions+=J

Keep this many lines above/below the cursor while scrolling.

set scrolloff=3

The title of the window to titlestring see :h title for better info.

set title

set foldmethod=indent set foldmethod=syntax

set foldmethod=manual

Easy cycle through tabs using Ctrl-PgUp/PgDown similar to FireFox This won't work in all terminal programs. some use this same key sequence to cycley through tabs, so you may need to disable this key shortcut in your terminal program for this mapping to work as advertised.

nmap <C-PageDown> :tabnext<CR>
nmap <C-PageUp> :tabprevious<CR>
imap <C-PageDown> :tabnext<CR>
imap <C-PageUp> :tabprevious<CR>

nmap :bn nmap :bp imap :bn imap :bp The above URL also has good stuff for autoclosing matching pairs, like (). One of the nicer minor features of TextMate is its treatment of highlighted text. If you have something highlighted and type a, it replaces the text, like other editors. If you type (, however, it wraps the selected text in parentheses. This is enormously useful. Luckily, it's very easy to recreate in Vim:

vnoremap ((  <ESC>`>a)<ESC>`<i(<ESC>
vnoremap ))  <ESC>`<i(<ESC>`><right>a)<ESC>
vnoremap {{  <ESC>`>a}<ESC>`<i{<ESC>
vnoremap }}  <ESC>`<i{<ESC>`><right>a}<ESC>

If allow " here, it messes up register selection So we use "" instead, and it works. Move this into doubleTap? vnoremap " >a"<ESC>

vnoremap ""  <ESC>`>a"<ESC>`<i"<ESC>
vnoremap ''  <ESC>`>a'<ESC>`<i'<ESC>
vnoremap ``  <ESC>`>a`<ESC>`<i`<ESC>
vnoremap [[  <ESC>`>a]<ESC>`<i[<ESC>
vnoremap ]]  <ESC>`<i[<ESC>`><right>a]<ESC>

When vimrc is edited, automatically reload it!

autocmd! bufwritepost .vimrc source ~/.vimrc

Big nasty viminfo setup. If you you have a smaller/slower system use the commented viminfo below, it's tuned down. track up to 20,000 files. store global marks. no more than 500 lines per register are saved 1000 lines of history save the buffer list

set viminfo='20000,f1,<500,:1000,@1000,/1000,%

HTML output options Use more modern css

let html_use_css = 1

wrap long lines

set wrap
set sidescroll=3

Some wordwrapp foo from kmandla

set formatoptions+=l
set lbr

set selection=inclusive
set shortmess=atI
set wildmenu
set wildmode=list:longest
set wildignore=*.swp,*.bak,*.pyc,*.pyo,*.class,*.6

set key timeout, good for remaps

set timeoutlen=300

I hate it when the cursorline is an underline This is how I make the cursorline a hightlight set cursorline hi clear CursorLine CursorLine really slows down php files There is something wrong with the PHP syntax plugin, as a work around we disable cursorline for PHP files. :(

au FileType php set nocursorline 

color schemes I have liked.

  • colo elflord " a low color dark theme. Great for the real console.
  • colo evening " dark theme, low color console friendly
  • colo xoria256 " a nice dark theme for 256 color terms
  • colo wombat256 " the classic wombat theme for 256 color terms
  • colo pyte " A white theme
  • colo mySlate
  • colo peaksea " A light theme
  • colo molokai " A dark pastelly theme, a little bisexual but very pleasing.
  • colo neutron " A very nice creamy light theme.
  • colo vylight " A light theme
  • colo jellybeans " A dark color full theme Explicitly say we want 256 colors when we find 256 in the TERM environmental variable. When this is set it can mess up using vim on a real console. Definitely in Fedora >= 11. So we try to be smart about it and only set it if we think it's wanted.

We default to a theme that works everywere. Then we see if we can upgrade to a better theme based on the environment.

colo evening " evening is a nice dark theme, usually available with a default install.

if has( "gui_running" )
    " I like a white based theme in GVim
    set cursorline
    hi clear CursorLine 

    " If using lucius
    let g:lucius_style = "light"
    " If using hemisu
    set background=light

    " colo lucius 
    colo hemisu
elseif $TERM =~ '256' || $COLORTERM =~ 'gnome-terminal'
    " Use a console friendly theme and force Vim to
    " use 256 colors if we think the console can handle it.
    set t_Co=256
    set cursorline
    hi clear CursorLine 

    if $TERM_META =~ 'white'
        set background=light
        let g:lucius_style = "light"
        set background=dark
        let g:lucius_style = "dark"

    colo lucius 
    " colo hemisu

set linenumbers on by default

set number 

Drupal rules If you edit a lot of php-drupal you should use these next few lines. If not, leave them commented out and I doubt you'll miss them.

   " augroup drupal_module
   "    autocmd BufRead *.module,*.inc set filetype=php
   " augroup END

autowrite: "on" saves a lot of trouble set autowrite be aggressive/paranoid and save often automatically.

set autowriteall
set autoread

interactive spell check works only in non-gui mode for now

map #sp :w<CR>:!ispell %<CR>:e %<CR> 

Use the next line to selectively enable spell checking for certain filetypes. I usually don't want spell checking when writting code, so only enable for thing with a lot of real words like text and markdown files.

au FileType text,markdown,rst setlocal spell spelllang=en_us
au FileType text,markdown,rst let b:NiceMenuContextRegex='[a-zA-Z0-9]' 

set mousemodel=popup " Make right mouse button work in gvim

set pastetoggle=<F2> " Allow toggling of paste/nopaste via F2

set hidden " Don't acutally close buffers, just hide them.

dictionary: english words first add any text based dictionaries to the list. Also, you can use C-X,C-K to autocomplete a word using the dictionary. Or, use C-X,C-S to check spelling on a word, fun stuff.

set dictionary+=/usr/share/dict/words,/usr/dict/words,/usr/dict/extra.words

Improved_Hex_editing ex command for toggling hex mode - define mapping if desired

command! -bar Hexmode call ToggleHex()

A more verbose pastetoggle

function! TogglePaste()
    if  &paste == 0
        set paste
        echo "Paste is ON!"
        set nopaste
        echo "Paste is OFF!"

Allow toggling of paste/nopaste via F2 set pastetoggle=

nmap <F2> <ESC>:call TogglePaste()<CR>
imap <F2> <ESC>:call TogglePaste()<CR>i

I like to put system library tags in a different tag file that is only generated once in a while.

set tags=tags;/
au FileType python set tags +=~/.tags/tags-python
au FileType c set tags +=~/.tags/tags-c
au FileType cpp set tags +=~/.tags/tags-cpp

I don't want variables and options saved in my views so remove the 'options' option from the default viewoptions setting. set viewoptions-=options

set viewoptions=cursor
set sessionoptions=winpos,localoptions

End More normal Vim tweaks.

Plugins and external addons LustyExplorer

nmap <silent> <c-l> <esc>:LustyBufferExplorer<CR>
imap <silent> <c-l> <esc>:LustyBufferExplorer<CR>

"" comments.vim A more elaborate comment set up. Use Ctr-C to comment and Ctr-x to uncomment This will detect file types and use oneline comments accordingle. Cool because you visually select regions and comment/uncomment the whole region. works with marked regions to. Just put it in your plugin directory. "" netrw Tree Style listing

let g:netrw_liststyle = 3

run the current buffer as a python script or run it through PyFlakes command.

au FileType python nmap <F1> <ESC>:w<CR>:!python %<CR>
au FileType python imap <F1> <ESC>:w<CR>:!python %<CR>
au FileType python nmap <F5> <ESC>:w<CR>:PyFlakes<CR>
au FileType python imap <F5> <ESC>:w<CR>:PyFlakes<CR>

let python_highlight_space_errors = 0

php synax check via 'php -l' uses my plugin/phplint.vim au FileType php nmap :w:PHPLint au FileType php imap :w:PHPLint use tidy I don't use this much, so may be buggy

au FileType html nmap <F5> <ESC>:w<CR>:HTMLTidyLint<CR>
au FileType html imap <F5> <ESC>:w<CR>:HTMLTidyLint<CR>

My own custom plugin/bashrun.vim Very simple, BashRun runs the buffer as a bash script and outputs errors into a quick fix windowl

au FileType sh,bash nmap <F1> <ESC>:w<CR>:!sh %<CR>
au FileType sh,bash imap <F1> <ESC>:w<CR>:!sh %<CR>
au FileType sh,bash nmap <F5> <ESC>:w<CR>:BashRun<CR>
au FileType sh,bash imap <F5> <ESC>:w<CR>:BashRun<CR>

au FileType sh,bash setlocal errorformat=%f\ line\ %l:\ %m

au FileType go setlocal errorformat=%f:%l:\ %m

Syntax checking entire python file
Usage: :make (check file)
:clist (view list of errors)
:cn, :cp (move around list of errors)

autocmd BufRead *.py set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
autocmd BufRead *.py set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m

The php syntax file and showing the cursorline don't play well together. If you find editing PHP files with cursorline enabled unbearably slow Use the following to disable the cursorline for PHP files

au FileType php set nocursorline 

Plugin Settings


Map Pep8 to F8

let g:pep8_map='<F8>'


I like to use CTRL-C to toggle comments

exec 'noremap <C-C> :TComment<cr>'
exec 'noremap <C-N> :TCommentBlock<cr>'

Lusty Explorer

   " nmap <C-d> <ESC>:LustyFilesystemExplorerFromHere<CR>
   " imap <C-d> <ESC>:LustyFilesystemExplorerFromHere<CR>
nmap <C-d> <ESC>:LustyFilesystemExplorer<CR>
imap <C-d> <ESC>:LustyFilesystemExplorer<CR>


Currently Unused let g:snips_author = 'Jeff Buttars'


autocmd FileType json set equalprg=json_reformat
autocmd FileType xml  set equalprg=xmllint\ --format\ -

doubleTap let g:loaded_doubleTap = 1

let g:DoubleTapInsertTimer = 0.8

Set NiceMenu Delay let g:loaded_nice_menu = 1 let g:NiceMenuDelay = '.6' let g:NiceMenuMin = 1

Sparkup options

I don't like default mapping, I actually use the default map for navigation let g:sparkupExecuteMapping = '' let g:sparkupNextMapping = ''


I still like sparkup, but I'm going to give Zen a shot. Change the mapping to my liking

let g:user_zen_leader_key = '<c-t>'

BellyButton settings

let g:BellyButton_javascript_jslint_options = {'white':'false', 'vars':'true','bitwise':'false',
            \'predef':"['Backbone', '_', 'console','window', 'Ext', 'jQuery', '$', 'cp', 'alert', 'confirm', 'document']"}


Set taglist plugin options

let Tlist_Use_Right_Window     = 0
let Tlist_Exit_OnlyWindow      = 1
let Tlist_Enable_Fold_Column   = 0
let Tlist_Compact_Format       = 1
let Tlist_File_Fold_Auto_Close = 1
let Tlist_Auto_Highlight_Tag   = 1
let g:ctags_statusline=1 " Display function name in status bar:
let generate_tags=1      " Automatically start script
let Tlist_Use_Horiz_Window=0 " Displays taglist results in a vertical window:

Shorter commands to toggle Taglist display

nnoremap TT :TlistOpen<CR>
map <F4> :TlistToggle<CR>

The default width of the vertically split taglist window is 30. This can be changed by modifying the 'Tlist_WinWidth' variable:

let Tlist_WinWidth = 60
let Tlist_Close_On_Select = 1 " Close Tlist when jumping to tag

By default, only the tag name will be displayed in the taglist window. If you like to see tag prototypes instead of names, set the 'Tlist_Display_Prototype' variable to 1. By default, this variable is set to zero and only tag names will be displayed.

let Tlist_Display_Prototype = 1


Misc People and places that I've gotten stuff from

IBM Vim series, quite good.

The g:maxLineLength variable is used by the MyStatusLine() function I define in hacks.vim

let g:maxLineLength=80

I put my small Vim hacks into a seperate file called hacks.vim There are things, often functions/commands, I don't want in my .vimrc but I also don't want to write a plugin for. I source it last thing

runtime hacks.vim