Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

603 lines (515 sloc) 15.233 kB
" =======================================
" Who: Jeremy Mack (@mutewinter)
" What: .vimrc of champions
" Version: 1.0 (this may never change because who versions dot files,
" honestly)
" =======================================
" ----------------------------------------
" Vundle
" ----------------------------------------
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle, required
Bundle 'gmarik/vundle'
" ---------------
" Plugin Bundles
" ---------------
" Navigation
Bundle 'ZoomWin'
Bundle 'wincent/Command-T'
" This fork is required due to remapping ; to :
Bundle 'christoomey/vim-space'
Bundle 'Lokaltog/vim-easymotion'
Bundle 'mutewinter/LustyJuggler'
Bundle 'kien/ctrlp.vim'
" UI Additions
Bundle 'mutewinter/vim-indent-guides'
Bundle 'Lokaltog/vim-powerline'
Bundle 'scrooloose/nerdtree'
Bundle 'Rykka/ColorV'
Bundle 'nanotech/jellybeans.vim'
Bundle 'tomtom/quickfixsigns_vim'
" Commands
Bundle 'scrooloose/nerdcommenter'
Bundle 'tpope/vim-surround'
Bundle 'tpope/vim-speeddating'
Bundle 'tpope/vim-fugitive'
Bundle 'godlygeek/tabular'
Bundle 'mileszs/ack.vim'
Bundle 'gmarik/sudo-gui.vim'
Bundle 'milkypostman/vim-togglelist'
" Automatic Helpers
Bundle 'IndexedSearch'
Bundle 'xolox/vim-session'
Bundle 'Raimondi/delimitMate'
Bundle 'scrooloose/syntastic'
Bundle 'ervandew/supertab'
Bundle 'gregsexton/MatchTag'
Bundle 'Shougo/neocomplcache'
" Language Additions
" Ruby
Bundle 'vim-ruby/vim-ruby'
Bundle 'tpope/vim-haml'
Bundle 'tpope/vim-rails'
Bundle 'tpope/vim-rake'
" JavaScript
Bundle 'pangloss/vim-javascript'
Bundle 'kchmck/vim-coffee-script'
Bundle 'leshill/vim-json'
Bundle 'itspriddle/vim-jquery'
" Other Languages
Bundle 'msanders/cocoa.vim'
Bundle 'mutewinter/taskpaper.vim'
Bundle 'mutewinter/nginx.vim'
Bundle 'timcharper/textile.vim'
Bundle 'ChrisYip/Better-CSS-Syntax-for-Vim'
Bundle 'acustodioo/vim-tmux'
Bundle 'hallison/vim-markdown'
Bundle 'xhtml.vim--Grny'
" MatchIt
Bundle 'matchit.zip'
Bundle 'kana/vim-textobj-user'
Bundle 'nelstrom/vim-textobj-rubyblock'
" Libraries
Bundle 'L9'
Bundle 'tpope/vim-repeat'
Bundle 'tomtom/tlib_vim'
filetype plugin indent on " Automatically detect file types. (must turn on after Vundle)
" Set leader to ,
" Note: This line MUST come before any <leader> mappings
let mapleader=","
" ----------------------------------------
" Platform Specific Configuration
" ----------------------------------------
if has('win32') || has('win64')
" Windows
source $VIMRUNTIME/mswin.vim
set guifont=Consolas:h10
set guioptions-=T " Toolbar
set guioptions-=m " Menubar
" Set height and width on Windows
set lines=60
set columns=120
" Windows has a nasty habit of launching gVim in the wrong working directory
cd ~
elseif has('gui_macvim')
" MacVim
" Custom Menlo font for Powerline
" From: https://github.com/Lokaltog/vim-powerline/wiki/Patched-fonts
set guifont=Menlo\ for\ Powerline:h12
" Hide Toolbar in MacVim
if has("gui_running")
set guioptions=egmrt
endif
" Use option (alt) as meta key.
set macmeta
endif
" ----------------------------------------
" Regular Vim Configuration (No Plugins Needed)
" ----------------------------------------
" ---------------
" Color
" ---------------
set background=dark
colorscheme jellybeans
" ---------------
" Backups
" ---------------
set backup
set backupdir=~/.vim/backup
set directory=~/.vim/tmp
" ---------------
" UI
" ---------------
set ruler " Ruler on
set nu " Line numbers on
set nowrap " Line wrapping off
set laststatus=2 " Always show the statusline
set cmdheight=2
set encoding=utf-8
" ---------------
" Behaviors
" ---------------
syntax enable
set autoread " Automatically reload changes if detected
set wildmenu " Turn on WiLd menu
set hidden " Change buffer - without saving
set history=768 " Number of things to remember in history.
set cf " Enable error files & error jumping.
set clipboard+=unnamed " Yanks go on clipboard instead.
set autowrite " Writes on make/shell commands
set timeoutlen=350 " Time to wait for a command (after leader for example)
set foldlevelstart=99 " Remove folds
set formatoptions=crql
" ---------------
" Text Format
" ---------------
set tabstop=2
set backspace=2 " Delete everything with backspace
set shiftwidth=2 " Tabs under smart indent
set cindent
set autoindent
set smarttab
set expandtab
set backspace=2
" ---------------
" Searching
" ---------------
set ignorecase " Case insensitive search
set smartcase " Non-case sensitive search
set incsearch
set hlsearch
set wildignore+=*.o,*.obj,*.exe,*.so,*.dll,*.pyc,.svn,.hg,.bzr,.git,.sass-cache,*.class
" ---------------
" Visual
" ---------------
set showmatch " Show matching brackets.
set matchtime=2 " How many tenths of a second to blink
" ---------------
" Sounds
" ---------------
set noerrorbells
set novisualbell
set t_vb=
" ---------------
" Mouse
" ---------------
set mousehide " Hide mouse after chars typed
set mouse=a " Mouse in all modes
" Better complete options to speed it up
set complete=.,w,b,u,U
" ----------------------------------------
" Bindings
" ----------------------------------------
" Fixes common typos
command W w
command Q q
map <F1> <Esc>
imap <F1> <Esc>
" Removes doc lookup binding because it's easy to fat finger
nmap K k
vmap K k
" Make line completion easier
imap <C-l> <C-x><C-l>
" Easier Scrolling (think j/k with left hand)
" All variations are mapped for now until I get used to one
" C/M/D + d (page up)
" C/M/D + f (page down)
nmap <C-d> <C-b>
if has("gui_macvim")
nmap <D-f> <C-f>
nmap <D-d> <C-b>
else
nmap <M-f> <C-f>
nmap <M-d> <C-b>
endif
" Use ; for : in normal and visual mode, less keystrokes
nnoremap ; :
vnoremap ; :
" double percentage sign in command mode is expanded
" to directory of current file - http://vimcasts.org/e/14
cnoremap %% <C-R>=expand('%:h').'/'<cr>
" ---------------
" Leader Commands
" ---------------
" Toggle spelling mode with ,s
nmap <silent> <leader>s :set spell!<CR>
" Edit vimrc with ,v
nmap <silent> <leader>v :e ~/.vim/vimrc<CR>
" Window Movement
nmap <silent> <C-h> :wincmd h<CR>
nmap <silent> <C-j> :wincmd j<CR>
nmap <silent> <C-k> :wincmd k<CR>
nmap <silent> <C-l> :wincmd l<CR>
" Previous Window
nmap <silent> <C-p> :wincmd p<CR>
" Equal Size Windows
nmap <silent> <leader>w= :wincmd =<CR>
" Window Splitting
nmap <silent> <leader>sh :split<CR>
nmap <silent> <leader>sv :vsplit<CR>
" Because I'm dyslexic
nmap <silent> <leader>hs :split<CR>
nmap <silent> <leader>vs :vsplit<CR>
nmap <silent> <leader>sc :close<CR>
" ----------------------------------------
" Auto Commands
" ----------------------------------------
if has("autocmd")
" No formatting on o key newlines
autocmd BufNewFile,BufEnter * set formatoptions-=o
" No more complaining about untitled documents
autocmd FocusLost silent! :wa
" When editing a file, always jump to the last cursor position.
" This must be after the uncompress commands.
autocmd BufReadPost *
\ if line("'\"") > 1 && line ("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
endif
" ----------------------------------------
" Plugin Configuration
" ----------------------------------------
" ---------------
" SuperTab
" ---------------
" Set these up for cross-buffer completion (something Neocachecompl has a hard
" time with)
let g:SuperTabDefaultCompletionType="<c-x><c-n>"
let g:SuperTabContextDefaultCompletionType="<c-x><c-n>"
" ---------------
" Neocachecompl
" ---------------
let g:neocomplcache_enable_at_startup=1
let g:neocomplcache_enable_auto_select=1 "Select the first entry automatically
let g:neocomplcache_enable_cursor_hold_i=1
let g:neocomplcache_cursor_hold_i_time=300
let g:neocomplcache_auto_completion_start_length=1
" Tab / Shift-Tab to cycle completions
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<S-TAB>"
" Required to make neocomplcache_cursor_hold_i_time work
" See https://github.com/Shougo/neocomplcache/issues/140
let s:update_time_save = &updatetime
autocmd InsertEnter * call s:on_insert_enter()
function! s:on_insert_enter()
if &updatetime > g:neocomplcache_cursor_hold_i_time
let s:update_time_save = &updatetime
let &updatetime = g:neocomplcache_cursor_hold_i_time
endif
endfunction
autocmd InsertLeave * call s:on_insert_leave()
function! s:on_insert_leave()
if &updatetime < s:update_time_save
let &updatetime = s:update_time_save
endif
endfunction
" ---------------
" Lusty Juggler
" ---------------
if has('unix')
" Allows for previous buffer on unix systems without most recent patch level
" that enable LustyJuggler to work
nnoremap <leader>, :e#<CR>
else
nnoremap <leader>, :LustyJugglePrevious<CR>
end
let g:LustyJugglerShowKeys=1 " Show numbers for Lusty Buffers
let g:LustyJugglerSuppressRubyWarning=1
" ---------------
" Syntastic
" ---------------
let g:syntastic_enable_signs=1
let g:syntastic_auto_loc_list=1
" Platform-specific config files
if has('win32') || has('win64')
let g:syntastic_jsl_conf=$HOME.'/.vim/config/windows/syntastic/jsl.conf'
let g:syntastic_disabled_filetypes=['sh'] " Disable .sh on Windows
endif
" ---------------
" NERDTree
" ---------------
nnoremap <leader>nn :NERDTreeToggle<CR>
nnoremap <leader>nf :NERDTreeFind<CR>
let NERDTreeShowBookmarks=1
let NERDTreeChDirMode=2 " Change the NERDTree directory to the root node
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" ---------------
" Indent Guides
" ---------------
let g:indent_guides_enable_on_vim_startup=1
" ---------------
" Session
" ---------------
let g:session_autosave=0
let g:session_autoload=0
nnoremap <leader>os :OpenSession<CR>
" ---------------
" SpeedDating
" ---------------
let g:speeddating_no_mappings=1 " Remove default mappings (C-a etc.)
nmap <silent><leader>dm <Plug>SpeedDatingDown
nmap <silent><leader>dp <Plug>SpeedDatingUp
nmap <silent><leader>dn <Plug>SpeedDatingNowUTC
" ---------------
" Tabular
" ---------------
nmap <Leader>t= :Tabularize /=<CR>
vmap <Leader>t= :Tabularize /=<CR>
nmap <Leader>t: :Tabularize /:\zs<CR>
vmap <Leader>t: :Tabularize /:\zs<CR>
nmap <Leader>t, :Tabularize /,\zs<CR>
vmap <Leader>t, :Tabularize /,\zs<CR>
nmap <Leader>t> :Tabularize /=>\zs<CR>
vmap <Leader>t> :Tabularize /=>\zs<CR>
" ---------------
" Fugitive
" ---------------
nmap <Leader>gc :Gcommit<CR>
nmap <Leader>gw :Gwrite<CR>
nmap <Leader>gs :Gstatus<CR>
nmap <Leader>gp :Git push<CR>
" Mnemonic, gu = Git Update
nmap <Leader>gu :Git pull<CR>
nmap <Leader>gd :Gdiff<CR>
" Exit a diff by closing the diff window
nmap <Leader>gx :wincmd h<CR>:q<CR>
" ---------------
" Zoomwin
" ---------------
" Zoom Window to Full Size
nmap <silent> <leader>wo :ZoomWin<CR>
" ---------------
" Command T and ctrlp.vim
" ---------------
" Ensure Ctrl-P isn't bound by default
let g:ctrlp_map = ''
if has('ruby')
" We've got Ruby, use Command T
" Conditional Mappings
if has("gui_macvim")
nnoremap <silent><D-t> :CommandT<CR>
else
nnoremap <silent><M-t> :CommandT<CR>
endif
" Leader Commands
nnoremap <leader>t :CommandT<CR>
nnoremap <leader>u :CommandT %%<CR>
else
" Fallback on ctrlp.vim if Ruby for Command T not available
" Conditional Mappings
if has("gui_macvim")
let g:ctrlp_map = '<D-t>'
else
let g:ctrlp_map = '<M-t>'
endif
" Leader Commands
nnoremap <leader>t :CtrlPRoot<CR>
endif
" Ensure max height isn't too large. (for performance)
let g:ctrlp_max_height = 10
let g:CommandTMaxHeight = 10
" Mapping from ctrlp we always use
if has('gui_macvim')
nnoremap <silent><D-u> :CtrlPCurFile<CR>
nnoremap <silent><D-y> :CtrlPMRUFiles<CR>
else
nnoremap <silent><M-u> :CtrlPCurFile<CR>
nnoremap <silent><M-y> :CtrlPMRUFiles<CR>
end
" Also map leader commands
nnoremap <leader>u :CtrlPCurFile<CR>
nnoremap <leader>y :CtrlPMRUFiles<CR>
" ---------------
" Powerline
" ---------------
" Keep ^B from showing on Windows in Powerline
if has('win32') || has('win64')
let g:Powerline_symbols = 'compatible'
elseif has('gui_macvim')
let g:Powerline_symbols = 'fancy'
endif
" ---------------
" jellybeans.vim colorscheme tweaks
" ---------------
" Make cssAttrs (center, block, etc.) the same color as units
hi! link cssAttr Constant
" ---------------
" Vundle
" ---------------
nmap <Leader>bi :BundleInstall<CR>
nmap <Leader>bu :BundleInstall!<CR> " Because this also updates
nmap <Leader>bc :BundleClean<CR>
" ----------------------------------------
" Functions
" ----------------------------------------
" ---------------
" OpenURL
" ---------------
if has('ruby')
ruby << EOF
require 'open-uri'
require 'openssl'
def extract_url(url)
re = %r{(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]\{\};:'".,<>?«»“”‘’]))}
url.match(re).to_s
end
def open_url
line = VIM::Buffer.current.line
if url = extract_url(line)
if RUBY_PLATFORM.downcase =~ /(win|mingw)(32|64)/
`start cmd /c chrome #{url}`
VIM::message("Opened #{url}")
else
`open #{url}`
VIM::message("Opened #{url}")
end
else
VIM::message("No URL found on this line.")
end
end
# Returns the contents of the <title> tag of a given page
def fetch_title(url)
if RUBY_VERSION < '1.9'
open(url).read.match(/<title>(.*?)<\/title>?/i)[1]
else
open(url, :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read.match(/<title>(.*?)<\/title>?/i)[1]
end
end
# Paste the title and url for the url on the clipboard in markdown format: [Title](url)
# Note: Clobbers p register
def paste_url_and_title
clipboard = VIM::evaluate('@+')
url = extract_url(clipboard)
if url and url.strip != ""
puts "Fetching title"
title = fetch_title(url)
VIM::command "let @p = '[#{title}](#{url})'"
VIM::command 'normal! "pp'
else
VIM::message("Clipboard does not contain URL: '#{clipboard[1..10]}'...")
end
end
EOF
" Open a URL
if !exists("*OpenURL")
function! OpenURL()
:ruby open_url
endfunction
endif
command! OpenUrl call OpenURL()
nnoremap <leader>o :call OpenURL()<CR>
" ---------------
" Paste link with Title
" ---------------
" Open a URL
if !exists("*PasteURLTitle")
function! PasteURLTitle()
:ruby paste_url_and_title
endfunction
endif
command! PasteURLTitle call PasteURLTitle()
map <leader>pt :PasteURLTitle<CR>
endif " endif has('ruby')
" ---------------
" Fix Trailing White Space
" ---------------
map <leader>ws :%s/\s\+$//e<CR>
command! FixTrailingWhiteSpace :%s/\s\+$//e
" ---------------
" Quick spelling fix (first item in z= list)
" ---------------
function! QuickSpellingFix()
if &spell
normal 1z=
else
" Enable spelling mode and do the correction
set spell
normal 1z=
set nospell
endif
endfunction
command! QuickSpellingFix call QuickSpellingFix()
nmap <silent> <leader>z :QuickSpellingFix<CR>
Jump to Line
Something went wrong with that request. Please try again.