Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 378 lines (315 sloc) 11.132 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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
set nocompatible " Why would I use vim if I wanted it to act like vi?
" Get pathogen going. Have to do 'set nocompatible' before calling pathogen.
call pathogen#infect()

" Make vim sane.
set noincsearch " incsearch is annoying
set nohlsearch " hlsearch is annoying
set foldclose= " Automatic foldclosing is irritating too
set noshowmode " I know what mode I'm in
set modeline
set scrolloff=8
set backupdir=~/.vim/tmp
set directory=~/.vim/tmp

" Beeping causes an increase in the urge to kill.
set noerrorbells " I hate bells
set visualbell " But saying noerrorbells doesn't do it all

" For whatever reason, we ahve to set these in an autocmd
autocmd VimEnter * set vb t_vb= " Make the visual bell zero time, so it doesn't blink.

" looks like vim's go support highlights leading and trailing whitespace.
" it's fucking annoying, so let's turn it off
let go_highlight_trailing_whitespace_error=0

" Sometimes the terminal isn't setup sanely, fix backspace.
imap <C-?> <C-h>

" Syntax and Color
if has("syntax")
  syn on
end
set t_Co=256
color desert256-jls

" Indentation. Do it my way.
set shiftwidth=2 " 2 spaces for shifting
set tabstop=2 " Tabs are 2 spaces wide.
set expandtab " When I hit tab, use spaces.
set autoindent
set nosmartindent
set cindent " Use c-style indentation
set cinkeys=!^F " Only indent when requested
set cinoptions=(0t0c1 " :help cinoptions-values

" Text folding
set foldmethod=marker

" I have a dark background...
set background=dark

" Keep state about my editing, thanks.
set viminfo='50,\"1000,:100,n~/.viminfo

" for slides
map <Leader>s :r!showoff add NEW SLIDE<CR>

" Make backups, just in case?
"set backup

" Interface goodness
set noruler
set laststatus=2 " Enable status bar
set showcmd " Show me the vi command in the ruler
set showmatch " Show me matching close braces
set ignorecase " Case insensitive searching
set smartcase " Unless I really mean case sensitive
set list " Show me whitespace where I care
"set number " Sometimes I like line numbers? Meh. Rarely.

" Some useful miscellaneous options
set listchars=tab:>- " In case I want to use the 'list' option
set matchpairs+=<:> " match < > with the % command, too
set complete=.,w,b,i,t,u " For great completion justice...
set backspace=indent,eol " allow rational backspacing in insert mode
set formatoptions=tcrqn
set comments=b:# " Most of my files use # for comments


" Set title string and push it to xterm/screen window title
set titlestring=vim\ %<%F%(\ %)%m%h%w%=%l/%L-%P
set titlelen=70
if &term == "screen"
  set t_ts=k
  set t_fs=\
endif
if &term == "screen" || &term == "xterm"
  set title
endif

" Some plugins like to contain documentation, hurray!
if isdirectory("~/.vim/doc")
  helptags ~/.vim/doc
endif

" Allow filetype plugins (ft_plugin stuff)
filetype on
filetype plugin on
filetype plugin indent on

" Mappings to jump me to the beginning of functions
nnoremap [[ ?{<CR>w99[{
nnoremap ][ /}<CR>b99]}
nnoremap ]] j0[[%/{<CR>
nnoremap [] k$][%?}<CR>

" Buffer movement
nnoremap H :prev<CR>
nnoremap L :next<CR>

" Miscellaneous auto commands
"autocmd BufEnter * silent! lcd %:p:h
autocmd Filetype mail set tw=72 noa
autocmd FileType perl set comments=f:#
autocmd FileType c,cpp set comments=s1:/*,mb:*,ex:*/,f://
autocmd FileType java set comments=s1:/*,mb:*,ex:*/,f://
autocmd FileType cvs set tw=72

" For the conque shell plugin
nnoremap <Leader>c :ConqueTermTab zsh<CR>

" Don't go into insert mode when the buffer is focused
let g:ConqueTerm_InsertOnEnter = 0
let g:ConqueTerm_ReadUnfocused = 1
let g:ConqueTerm_TERM = 'xterm'

" Tagbar plugin
nnoremap <silent> <Leader>f :TagbarToggle<CR>

" Command-T plugin
set wildignore+=*.o,*.so,*.6,*.pyc,build,vendor,tmp
nnoremap <silent> <Leader>t :execute "CommandT " . b:gitroot<CR>
nnoremap <silent> <Leader>b :CommandTBuffer<CR>
" control+/ shows up in the terminal as ^_, so map C-_ to make it happen.
nnoremap <silent> <C-_> :execute "CommandT " . b:gitroot<CR>

" These mappings don't actually work, probably because conqueshell happens
" afterwards. Hmmm
"autocmd FileType conque_term inoremap <silent> <buffer> <C-n> <Esc>:tabnext<CR>
"autocmd FileType conque_term inoremap <silent> <buffer> <C-p> <Esc>:tabnext<CR>

" Programming stuff
ab XXX: TODO(sissel):

" Tab and Window navigation
noremap <C-n> :tabnext<CR>
noremap <C-k>n :tabnext<CR> " muscle memory
noremap <C-k><C-n> :tabnext<CR> " muscle memory
noremap <C-p> :tabprev<CR>
noremap <C-k>p :tabprev<CR> " muscle memory
noremap <C-k><C-p> :tabprev<CR> " muscle memory
noremap <C-j> <C-W>j
noremap <C-k> <C-W>k
noremap <C-h> <C-W>h
noremap <C-l> <C-W>l

" gVim specific settings, not that I really use this.
set guioptions-=T " Remove the toolbar and menubar
set guioptions-=m
set guioptions-=r " Remove right- and left-hand scrollbars
set guioptions-=L
set guioptions+=c " Console-based dialogs for simple queries
set guifont=suxus " Yay fonts!

" Let us toggle the menu
let g:menubar=0
map <silent> <Del> :if g:menubar == 1<CR>:set guioptions-=m<CR>:let g:menubar = 0<CR>:else<CR>:set guioptions+=m<CR>:let g:menubar = 1<CR>:endif<CR>

" Turn blinking off
set guicursor=a:block-blinkoff1

" PyBloxsom stuff
augroup pybloxsom
  autocmd BufReadPost */s/entries/*/*.txt call Pybloxsom_checkdate()
  autocmd BufNewFile */s/entries/*/*.txt call Pybloxsom_putdate()
  autocmd BufWritePost */s/entries/*/*.txt call Pybloxsom_fudgedate()
augroup end

function! Pybloxsom_checkdate()
" Look in the file for '#mdate foo' metadata
  normal 1G
  let dateline = search("^#mdate")

" If not found, append the mdate of the file to line 2
  if dateline < 1
" hack for using date+stat to generate the right date format.
    let date = system("date -d \"January 1 1970 00:00:00 $(stat -c %Z " . expand("%") . ") seconds 8 hours ago\" \"+#mdate %b %d %H:%M:%S %Y\"")
" Add the date to the file on line 1
    1put=date
  endif
endfunction

function! Pybloxsom_putdate()
  let date=strftime("#mdate %b %e %H:%M:%S %Y")
  1put=date
  goto 1
endfunction

function! Pybloxsom_fudgedate()
" Mark our position
  normal mZ

" Find mdate
  let l=search("^#mdate")
  let l=strpart(getline(l), 7)
" for freebsd?
"let cmd="date -j -f '%b %e %H:%M:%S %Y' '" . l . "' +%y%m%d%H%M"
"let touchtime=system(cmd)
"let touchcmd="touch -t '" . strpart(touchtime,0,strlen(touchtime)-1) . "' '" . expand("%") . "'"
  
  let touchcmd="touch -d '" . l . "' " . expand("%")
  call system(touchcmd)
" Reload the file (make vim notice the date change)
  e

" Jump back to our old position
  normal `Z
endfunction

" Things I don't want you to see! Neener neener neener.
if filereadable(glob("~/.vimrc-private"))
  source ~/.vimrc-private
endif

" Let me read files in perforce.
autocmd BufReadCmd //depot/* exe "0r !p4 print -q <afile>"
autocmd BufReadCmd //depot/* 1
autocmd BufReadCmd //depot/* set readonly

" Indent helpers
"inoremap <C-f> <ESC>:call ReIndent(1)<CR>
function! ReIndent(in_insert_mode)
  let l:col = col(".")
  let l:lnum = line(".")

" set append = 1, if we're at the end of the line.
  let l:linelen = strlen(getline(l:lnum))
  let l:append = (l:col >= l:linelen)

  let l:indent_ok = 0
  if IndentToParen(l:lnum, 1)
    let l:indent_ok = 1
  elseif IndentToParen(l:lnum, 0)
    let l:indent_ok = 1
  endif

" Move back to our original position
  let l:linedelta = strlen(getline(l:lnum)) - l:linelen
  call setpos('.', [0, l:lnum, l:col + l:linedelta, 0])

  if l:indent_ok == 0
"Both indent attempts failed, try using == instead
    normal ==
  endif

  if a:in_insert_mode
    if l:append == 1
      startinsert!
    else
      normal l
      startinsert
    endif
  endif
endfunction

function! IndentToParen(lnum, assume_unclosed)
" Search for '(' on the previous line
  let l:ret = 1
  let l:lnum = a:lnum
  let l:prevlnum = prevnonblank(l:lnum - 1)
  let l:oldline = getline(l:lnum)

  if a:assume_unclosed
" insert a ), find what it matches, indent to that open paren?
    call setline(l:lnum, ")")
  else
    call setpos('.', [0, l:prevlnum, 0, 0])
    execute "normal $F)"
  endif

  let [l:slnum, l:scol] = searchpairpos('(', '', ')', 'nbW')

  if a:assume_unclosed
    call setline(l:lnum, l:oldline)
  endif

  if l:slnum[0] != 0
" Trim leading space/tabs
    call setpos('.', [0, l:lnum, 0, 0])
    s/^[ ]*//
" Set the line with new indentation
    if a:assume_unclosed == 0
      let l:scol = indent(l:slnum)
    endif
    call setline(l:lnum, repeat(" ", l:scol) . getline(l:lnum))

" Turn spaces into tabs on this line, if necessary.
    .retab!
  else
"echo "No match found on IndentToParen " . a:assume_unclosed
    let l:ret = 0
  endif
  return l:ret
endfunction

let g:lastfile = ""
nmap <space>s :call SwitchHeaderAndCode()<CR>

function! SwitchHeaderAndCode()
  let l:basefile = expand("%:t:r")
  let l:ext = expand("%:e")
  let l:oldfile = expand("%")

  if g:lastfile
    exec "find " . g:lastfile
  elseif l:ext == "cpp"
    let g:lastfile = expand("%")
    exec "find " . l:basefile . ".h"
  elseif l:ext == "h"
    let g:lastfile = expand("%")
    exec "find " . l:basefile . ".cpp"
  endif
endfunction

function! GPPErrorFilter()
  silent! %s/->/ARROW/g
  silent! %s/>>/RIGHTSHIFT/g
  silent! %s/<</LEFTSHIFT/g
  while search("<", "wc")
    let l:line = getline(".")
    let l:col = col(".")
    let l:char = l:line[l:col - 1]
    if l:char == "<"
      normal d%
    else
      break
    endif
  endwhile
  silent! %s/ARROW/->/g
  silent! %s/RIGHTSHIFT/>>/g
  silent! %s/LEFTSHIFT/<</g
  silent %!awk '/: In/ { print "---------------"; print }; \!/: In/ {print }'
endfunction

function! s:ExecuteInShell(command)
  let command = join(map(split(a:command), 'expand(v:val)'))
  let winnr = bufwinnr('^' . command . '$')
  let output = system(command)
  if v:shell_error != 0
    execute winnr < 0 ? 'botright new ' . fnameescape(command) : winnr . 'wincmd w'
    setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap number

    normal 1GdG
    call append(".", split(output, "\n"))
"execute 'resize ' . line('$')
    resize 5
    redraw
    autocmd BufEnter <buffer> resize 15
    autocmd BufLeave <buffer> resize 5
    execute 'au BufUnload <buffer> execute bufwinnr(' . bufnr('#') . ') . ''wincmd w'''
    execute 'nnoremap <silent> <buffer> <LocalLeader>r :call <SID>ExecuteInShell(''' . command . ''')<CR>'
    execute 'nnoremap <silent> <buffer> q :q<CR>'
  else
" Success, if the previous output buffer exists, delete and close it.
    if winnr >= 0
      execute "bdelete" winnr
    end
  endif
endfunction
command! -complete=shellcmd -nargs=+ Shell call s:ExecuteInShell(<q-args>)
command! SelfTest Shell dk test %
nnoremap <Leader>t :SelfTest<CR>

"autocmd BufWritePost *.rb SelfTest
"autocmd BufWritePost *.pp SelfTest
Something went wrong with that request. Please try again.