Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 324 lines (264 sloc) 10.803 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
set nocompatible " screw vi-compatible features
set encoding=utf-8 " utf-8 is fun
set nowrap

call pathogen#infect() " pathogen
source ~/.vim/filetypes " load awesome filetypes
runtime macros/matchit.vim " load matchit (included with vim)

set hidden " don't yell when hiding modified buffers
set history=1000 " lots o' history
set clipboard=unnamed " link vim and the system's clipboards
set visualbell " no beeping!
set showmatch " flash matching brackets and parens
set scrolloff=3 " keep a few lines visible above and below cursor
" set scrolloff=1 " keep a few lines visible above and below cursor
set backupdir=~/.vim/_backup// " store backup files
set directory=~/.vim/_tmp// " store swap files
set undodir=~/.vim/_undo " store undo history
set undofile
set undolevels=1000
set undoreload=10000
set splitbelow " I like my splits opening below
set splitright " and my vsplits opening to the right

set showcmd " show partial commands below status line
set cmdheight=1 " 1-line command window
set textwidth=78 " break long lines at 78 characters

""" Searching
set hlsearch " highlight search results
set incsearch " highlight matches while searching
set ignorecase " ignore case when searching.
set smartcase " override ignorecase if search contains upper case

""" Whitespace
set shiftwidth=2 " use 2 spaces for indentation
set tabstop=2 " use 2 spaces when tabbinb
set expandtab " use spaces instead of tabs because tabs are evil
set smarttab " backspacing deletes space-expanded tabs
set nojoinspaces " never use two spaces when joining lines
set backspace=indent,eol,start " allow backspacing over autoindent,
" line breaks, and start of insert

""" Tab completion
set wildmenu
set wildmode=list:full,full
set wildignore+=tmp/**,vendor/**,exec/**,gemfiles/**

" """ Show invisible characters
" set listchars="" " reset the listchars
" set listchars+=tab:\ \ " show tab as two spaces
" set listchars+=trail:. " show trailing whitespace as .
" set listchars+=extends:> " the character to show in the last column when
" " wrap is off and line is too long.
" set listchars+=precedes:< " the character to show in the first column when
" " wrap is off and line is too long.

""" Visual
syntax on " highlight my syntax plz
set cursorline " highlight cursor line
set colorcolumn=-1,-0 " highlight the 77th and 78th columns
set t_Co=256 " more than 8 colors, kthx
set gfn=Source\ Code\ Pro:h18 " Menlo is another great font
set fillchars= " don't need characters when we have colors
set background=dark
colorscheme base16-default
" colorscheme larry

" PRESENTATION
" set scrolloff=1
" set background=light

""" Color tweaks
highlight ColorColumn ctermbg=233
highlight TabLine ctermbg=0
highlight TabLineSel ctermbg=0
highlight TabLineFill ctermbg=0

""" Status bar
set laststatus=2
set statusline=\ %f%(\ [%M%R%W%H]%) " filename
set statusline+=%= " right align
set statusline+=%-14.(%l/%L,%v%)\ %<%P\ " offset

" Set window/terminal title
set title
set titlestring=%F " /path/to/file.txt (Vim)

""" Plugin Configuration
let g:ftplugin_sql_omni_key = '<C-X>' " use C-X instead of C-C in sql.vim
let g:CommandTMaxHeight=10
let g:CommandTMinHeight=4
let g:netrw_liststyle=4

""" Mappings
let mapleader = ","

" I like comma for a leader, but I'd still like to use the original Normal
" mode comma command. Double comma should suffice.
nmap <leader><leader> ,<ESC>
nmap <leader>s :w<enter>

" Can't be bothered to understand ESC vs <c-c> in insert mode
" https://github.com/garybernhardt/dotfiles/blob/master/.vimrc#L117-118
imap <c-c> <esc>

" Disable backspace to force use of <C-h> and <C-w>
inoremap <bs> <nop>

command! W :w " alias :w as :W to fight accidental typos

" Easy expansion of the active file directory. Cite: Practical Vim pg 94.
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'

" delete the active buffer keeping the split open
map <leader>x :bprevious<cr>:bdelete #<cr>
map <leader>X :bdelete<cr>

nmap <leader>u :GundoToggle<CR>
nmap <leader><cr> :nohlsearch<CR>
nmap <leader>S :set spell<CR>]s
nmap <leader>ns :set nospell<CR>
nmap <leader>a :Ag<space>
nmap <leader>A :Ag!<space>
nmap <leader>w :Ag<space><C-r><C-w><cr>
nmap <leader>W :Ag!<space><C-r><C-w><cr>

" yank until the end of the line
nmap Y y$

" split and tab management and navigation
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-S-l> <C-w>l
nmap <leader>t :tabnext<cr>
nmap <leader>T :tabprevious<cr>

""" Ruby
imap <C-l> <Space>=><Space>
nmap <leader>R i, record: :new_episodes<ESC>

""" Tabularize
nmap <leader>j vip:Tabularize json<CR>
vmap <leader>j :Tabularize json<CR>
vmap <leader>: :Tabularize first_colon<CR>
vmap <leader>l :Tabularize hash_rocket<CR>
vmap <leader>= :Tabularize first_equals<CR>
vmap <leader>' :Tabularize first_single_quote<CR>
vmap <leader>" :Tabularize first_double_quote<CR>
vmap <leader>{ :Tabularize first_left_stash<CR>
vmap <leader>} :Tabularize first_right_stash<CR>
vmap <leader>\| :Tabularize bar<CR>

""" **Embolden** selection
nmap <leader>* viWS*gvS*
vmap <leader>* S*gvS*

""" Open file in Marked
map <leader>m :silent !open "%" -a /Applications/Marked.app<cr>:redraw!<cr>

""" Select the last pasted text
nmap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'


augroup Config
  autocmd!

" Reload vimrc after save.
  autocmd BufWritePost ~/.vim/vimrc source ~/.vim/vimrc

  autocmd BufWritePost ~/.vim/colors/larry.vim colorscheme larry

" Reload tmux.conf after save.
  autocmd BufWritePost ~/Code/dotfiles/.tmux.conf call system('tmux source-file ~/.tmux.conf')

" Create the directory if it doesn't exist.
  autocmd BufNewFile * silent !mkdir -p $(dirname %)

" Don't syntax highlight markdown because it's often wrong
  autocmd! FileType markdown setlocal syn=off
augroup END

augroup CoffeeScript
  autocmd!
  autocmd BufNewFile,BufReadPost,BufEnter *.coffee imap <C-l> <Space>->
  autocmd BufLeave *.coffee imap <C-l> <Space>=><Space>
augroup END

augroup PlantUML
  autocmd!
  autocmd BufNewFile,BufReadPost,BufEnter *.plantuml nmap <leader>. :w<CR>:!java -jar /Users/Larry/.bin/plantuml.jar %<CR>
  autocmd BufLeave *.plantuml nmap <leader>. :call RunTestFile()<CR>
augroup END

augroup Ronn
  autocmd!
  autocmd BufNewFile,BufReadPost,BufEnter *.ronn nmap <leader>> :silent :!clear<cr>:w<cr>:!gronn<cr>
  autocmd BufLeave *.ronn nmap <leader>> :silent :!clear<cr>:w<cr>:!ruby -Ilib %<cr>
augroup END

augroup SizeWindow
  autocmd!
  autocmd WinEnter * call SizeWindow()
augroup END

function! SizeWindow()
  if winwidth(winnr()) < 79
    exec "vertical resize 79"
  end
endfunction

" Pipe the selection to the CoffeeScript compile and print the result.
function! CompileCoffee() range
  let code = shellescape(join(getline(a:firstline, a:lastline), "\n"))

" shellescape() escapes newlines and encloses in single quotes. Code needs
" to be wrapped in double quotes and use real newlines in order to be
" processed correctly.
  let code = substitute(code, "\\\\\n", "\n", "g")

  echo system("echo " . code . "| coffee -scb")
endfunction

vmap <leader>c :call CompileCoffee()<CR>

" Shamelessly ripped from Gary Bernhardt's vimrc
" https://github.com/garybernhardt/dotfiles/blob/master/.vimrc
function! RunRuby()
" Write the file and run tests for the given filename
  w
  silent !echo;echo;echo;echo;echo
  exec ":!ruby " . expand("%")
endfunction

function! RunTestFile()
  let in_spec_file = match(expand("%"), '_spec.rb$') != -1
  let in_test_file = match(expand("%"), '_test.rb$') != -1
  let in_clj_file = match(expand("%"), '.clj$') != -1

  if in_spec_file
    call SetTestFile()
  elseif in_test_file
    call SetTestFile()
  elseif in_clj_file
    call SetTestFile()
  elseif !exists("g:grb_test_file")
    return
  end

  call ChooseTestRunner(g:grb_test_file)
endfunction

function! SetTestFile()
" Set the spec file that tests will be run for.
  let g:grb_test_file=@%
endfunction

function! ChooseTestRunner(filename)
  write
  silent !echo;echo;echo;echo;echo

  let run_specs = match(a:filename, '_spec.rb$') != -1
  let run_tests = match(a:filename, '_test.rb$') != -1
  let run_clj = match(a:filename, '.clj$') != -1

  if run_specs
    call RunSpecs(a:filename)
  elseif run_tests
    call RunTests(a:filename)
  elseif run_clj
    call RunLein(a:filename)
  endif
endfunction

function! RunSpecs(filename)
" exec ":!ruby -Ilib -Ispec " . a:filename
  silent exec ":!echo rspec " . a:filename
  exec ":!time rspec " . a:filename
endfunction

function! RunTests(filename)
  silent exec ":!echo ruby -Ivendor/bundle -Itest -Ispec -Ilib " . a:filename
  exec ":!time ruby -Ivendor/bundle -Itest -Ispec -Ilib " . a:filename
endfunction

function! RunLein(filename)
  silent exec ":!echo lein test"
  exec ":!time lein test"
endfunction

nmap <leader>. :call RunTestFile()<CR>
nmap <leader>> :silent !clear<cr>:w<cr>:!ruby -Ivendor/bundle -Itest -Ispec -Ilib %<cr>

" Run a given vim command on the results of fuzzy selecting from a given shell
" command. See usage below.
function! SelectaCommand(vim_command)
  try
    silent let selection = system("git ls-files --modified --cached --other --exclude-standard | uniq | sort | selecta")
  catch /Vim:Interrupt/
" Swallow the ^C so that the redraw below happens; otherwise there will be
" leftovers from selecta on the screen
    redraw!
    return
  endtry
  redraw!
  exec a:vim_command . " " . selection
endfunction

" Find all files in all non-dot directories starting in the working directory.
" Fuzzy select one of those. Open the selected file with :e.
nnoremap <leader>f :call SelectaCommand(":edit")<cr>
nnoremap <leader>F :call SelectaCommand(":tabedit")<cr>
nnoremap <leader>V :call SelectaCommand(":vsplit")<cr>
nnoremap <leader>S :call SelectaCommand(":split")<cr>

augroup xmpfilter
  autocmd!

  autocmd FileType ruby nmap <buffer> <leader>m <Plug>(xmpfilter-mark)
  autocmd FileType ruby xmap <buffer> <leader>m <Plug>(xmpfilter-mark)
  autocmd FileType ruby nmap <buffer> <leader>r <Plug>(xmpfilter-run)
  autocmd FileType ruby xmap <buffer> <leader>r <Plug>(xmpfilter-run)
augroup END
Something went wrong with that request. Please try again.