" My vimrc 
" based on Aur�. Vieux truc since 1996 ;)
if has("syntax") && &t_Co > 2
  syntax on
endif

if has("autocmd")
 filetype plugin indent on
endif " has ("autocmd")

" don't don't out in insert mode
set noinsertmode
" allow us to backspace before an insert
set backspace=2
" tabs are to be set at 4 spaces
set tabstop=4
" show the ruler for editing
set ruler
" turn off the mouse in the xterm
" set mouse=a
" show the command in the status line
set showcmd
" always have a status line
set laststatus=2
" Highlighting Matches
set hlsearch

" Virginie Vacca
set autoread        " r�percute dynamiquement les modifs (vim5)
set incsearch       " Incremental search (comme emacs :)
set lazyredraw      " redraw screen while executing Cmds
set nobackup        " Don't keep a backup file
set nocompatible    " Use Vim defaults (much better!)
set path=.,~/Documents,/var/www/,$VIMRUNTIME/syntax/
set whichwrap=<,>,[,]   " Allow cursor keys to wrap around lines.
set viminfo=%,'50,\"100,:100,n~/.vim/.viminfo
" Be nice and quiet
set noerrorbells
set visualbell
set t_vb=

set title
set showmode
"set showmatch " matching bracket
" but not all the messages
set shortmess=atTI
set ttyscroll=0
" Useful for CTRL-] stuff.
"set   iskeyword=@,48-57,_,192-255,-,.

"     comments default: sr:/*,mb:*,el:*/,://,b:#,:%,:XCOMM,n:>,fb:-
"set   comments=b:#,:%,fb:-,n:>,n:),sr:/*,mb:*,el:*/,n:###,n:\"
set joinspaces

" Email/News (mega bordel mais �a marche)
" ==========
"
" Clear Empty Lines
map ,cel :%s/^\s\+$//e^M
map ,cqoq :%s/^>\s\+/> /e^M

" remove all > On blah... stuff left behind in quoted text - huggie
"nmap ,cqmh :g/^\([>*] \)\+On.*wrote:$/d<CR>
" vim doesn't yet do matching on multilines AFAIK.
"map ,db :1,20s/\(^On.*wrote:$\)\n\+/\1/^M
" Clear blank lines after my On foo wrote: 
map ,db /^>.*On.*wrote:$/e^Mjmt:.,.s/^$//gec^Mq/^.\+$^Mkmb`td'b^M

" Kill empty quoted lines
nmap ,ceql :g/^\(> \)\{2,}\s*$/d<CR>^M
nmap ,cqel :%s/^> \s*$//<CR>^M
" remove quoted sig
map ,rq1 /^> *-- ^Mmt/^[^>]*$^Mkmb``d'b^M
map ,rq2 /^> *-----------^Mmt/^[^>]*$^Mkmb``d'b^M
map ,rq3 /^> *___________^Mmt/^[^>]*$^Mkmb``d'b^M

" Turn all blocks of empty lines (within current visual)
" into *one* empty line:
map ,dl :g/^$/,/./-j<CR>^M

" Condense multiple Re:'s
map ,re 1G/^Subject:<CR>:s/\(Re: \)\+/Re: /e<CR>^M

" Sven's wondeful change subject macro
map ,cs 1G/^Subject: <CR>yypIX-Old-<ESC>-W
vmap ,qp :s/^/> /<CR>^M

" this clears out the old colors before we begin
"highlight Constant    NONE
"highlight Delimiter   NONE
"highlight Directory   NONE
"highlight Error       NONE
"highlight ErrorMsg    NONE
"highlight Identifier  NONE
"highlight LineNr      NONE
"highlight ModeMsg     NONE
"highlight MoreMsg     NONE
"highlight Normal      NONE
"highlight NonText     NONE
"highlight PreProc     NONE
"highlight Question    NONE
"highlight Search      NONE
"highlight Special     NONE
"highlight SpecialKey  NONE
"highlight Statement   NONE
highlight StatusLine  NONE
"highlight StatusLineNC NONE
"highlight Title       NONE
"highlight Todo        NONE
"highlight Type        NONE
"highlight Visual      NONE
"highlight WarningMsg  NONE
" these are the new superior colors
"highlight Comment     term=bold ctermfg=5 ctermbg=0 guifg=#FF005F guibg=gray
"highlight Constant    term=underline ctermfg=6 guifg=#FF2f8f
"highlight Delimiter   term=bold cterm=bold ctermfg=1 gui=bold guifg=Red
"highlight Directory   term=bold ctermfg=DarkBlue guifg=Blue
"highlight Error       term=standout cterm=bold ctermbg=1 ctermfg=1 gui=bold guifg=red
"highlight ErrorMsg    term=standout cterm=bold ctermfg=1 gui=bold guifg=red
"highlight Identifier  term=underline ctermfg=3 guifg=yellow3
"highlight LineNr      term=underline cterm=bold ctermfg=3 guifg=Brown
"highlight ModeMsg     term=bold cterm=bold ctermfg=3 ctermbg=1 guifg=yellow2 guibg=red
"highlight MoreMsg     term=bold cterm=bold ctermfg=2 gui=bold guifg=Green
"highlight NonText     term=bold ctermfg=2 guifg=green3
"highlight Normal      ctermfg=white ctermbg=black guifg=grey90 guibg=#000020
"highlight PreProc     term=underline ctermfg=14 guifg=cyan
"highlight Question    term=standout cterm=bold ctermfg=2 gui=bold guifg=Green
"highlight Search      term=reverse ctermbg=2 guibg=Yellow
"highlight Special     term=bold ctermfg=5 guifg=SlateBlue
"highlight SpecialKey  term=bold ctermfg=DarkBlue guifg=Blue
"highlight Statement   term=bold ctermfg=2 gui=bold guifg=green3
highlight StatusLine  term=reverse cterm=bold ctermfg=3 ctermbg=4 guifg=wheat guibg=#2f4f4f
"highlight StatusLineNC term=bold ctermfg=3 ctermbg=2 guifg=#071f1f guibg=#5f9f9f
"highlight Title       term=bold cterm=bold ctermfg=4 gui=bold guifg=Blue
"highlight Todo        term=bold ctermfg=red ctermbg=yellow guifg=red guibg=yellow1 gui=bold
"highlight Type        term=underline cterm=bold ctermfg=3 guifg=yellow3 gui=bold
"highlight Visual      term=reverse cterm=bold ctermfg=6 ctermbg=5 guifg=yellow guibg=blue
"highlight WarningMsg  term=standout cterm=bold ctermfg=1 ctermbg=4 guifg=Red

" all of this stuff allows me to write gzipped files natively...cool eh?
"autocmd BufRead *.gz set bin|%!gunzip
"autocmd BufRead *.gz set nobin
"autocmd BufWritePre *.gz %!gzip
"autocmd BufWritePre *.gz set bin
"autocmd BufWritePost *.gz undo|set nobin
"autocmd FileReadPost *.gz set bin|'[,']!gunzip
"autocmd FileReadPost set nobin

" Sp�cial fichier ChangeLog
autocmd BufRead ChangeLog set expandtab

" Divers...
set wig=*.o,*.obj,*~
set sw=4
set cin
set ai
set ul=200
set ch=1
set wc=<Tab>
set smd
set bs=2
"set bg=dark
"set nowrap
set smartindent
" Automatically save before commands like :next and :make
set autowrite

" instructions for VIM on processing this file
"vim:ts=3

" Taille du texte et des tabluations selon les fichiers que l'on �dite
autocmd BufRead *.tex,*.latex set tw=100
autocmd BufRead *.tex,*.latex set nocin
autocmd BufRead .followup,.article,.letter,mutt* set tw=72
autocmd BufRead .followup,.article,.letter,mutt* set tabstop=8
autocmd BufRead .followup,.article,.letter,mutt* set nocin

" Mail and News autocommands
" ==========================
"au BufRead ~/.article*,~/.followup,mutt* source ~/.vim/words_tools.vim
"au BufRead ~/.article*,~/.followup,mutt* source ~/.vim/Mail_mutt_alias.set

" Remove quoted On blah stuff
"au BufRead ~/.article*,~/.followup,mutt* :silent! normal ,cqmh
" Remove many Re:'s from the Subject line
au BufRead ~/.article*,~/.followup,mutt* normal ,re
" Remove empty quoted lines
au BufRead ~/.article*,~/.followup,mutt* normal ,ceql
" Remove the empty lines after an unquoted On blah stuff
au BufRead ~/.article*,~/.followup,mutt* normal ,db
" Clear empty lines and turn into space to write in
au BufRead ~/.article*,~/.followup,mutt* normal ,cqel
au BufRead ~/.article*,~/.followup,mutt* normal ,cel
au BufRead ~/.article*,~/.followup,mutt* normal ,cqoq
" remove quoted signatures
au BufRead ~/.article*,~/.followup,mutt* normal ,rq1
au BufRead ~/.article*,~/.followup,mutt* normal ,rq2
au BufRead ~/.article*,~/.followup,mutt* normal ,rq3
" Remove blocks of empty lines
au BufRead ~/.article*,~/.followup,mutt* :silent! normal ,dl

" Aur�
nnoremap Q gq
vnoremap Q gq
"map F {!}par -w76 -gtjq

" multiple indent (delaballe merci Matt Kunze)
noremap < <<CR>gv
noremap > ><CR>gv

" Scroll in insert mode CRTL E and CTRL Y
inoremap <C-E> <C-X><C-E>
inoremap <C-Y> <C-X><C-Y>

"noremap <F8> :so `~/bin/vimspell.sh %`<CR><CR>
"noremap <F7> :syntax clear SpellErrors<CR>

" Mail (plus utilis� car automatique cf au dessus)
"
" ,kqs = kill quoted signature 
"map ,kqs G?^> *-- $<CR>d}

" ,kpq kill SuperCite (aka PowerQuote) quote (replacing it by `>')
"map ,kpq :%s/^> *[a-zA-Z]*>/> >/<C-M>

" reformat body text to current textwidth
"map ,ref 1G/^$<CR>V/^-- $<CR><Up>Q1G
"map ,ref G?^-- $<CR><Up>V1G/^[ \t]*$<CR>Q1G

" Correction orthgraphique (megadelaballe)
map ,i :w<CR>:!aspell --mode=email -c %<CR>:e %<CR>
map ,I :w<CR>:!aspell -c %<CR>:e %<CR>

" snip (merci Nico)
vmap <buffer> ;snip c>[...]<Esc>

" Mettre/virer un bloc en commentaire
vmap <buffer> ;com :s/^/#/g<CR>
vmap <buffer> ;uncom :s/^#//g<CR>

" Affiche la date au format RFC822 - ftplugin/debchangelog. Nico
function! Date822()
    let savelang = v:lc_time
    execute "language time C"
    let dateandtime = strftime("%a, %d %b %Y %X %z")
    execute "language time " . savelang
    return dateandtime
endfunction
iab debdate <C-R>=Date822()<CR>

" Racourcis sympas
" dans le texte
"iab ca �a
"iab Ca �a
"iab << �
"iab >> �
"iab etre �tre
"iab meme m�me
iab ladate <C-R>=strftime("%A %d %B %Y")<CR>
iab lheure <C-R>=strftime("%H:%M")<CR>
iab cuthere -------------------- cut here --------------------<CR><CR>-------------------- cut here --------------------

" Sp�cial Popossum
vmap <buffer> ,pik :s/ / pik /g<CR>
vmap <buffer> ,unpik :s/ pik / /g<CR>

map ,n :NERDTreeToggle<CR>
vmap b :!git blame =expand("%:p")  \| sed -n =line("',=line("'>") p 
colorscheme delek
filetype plugin on

set tabstop=4 shiftwidth=4 expandtab
execute pathogen#infect()
syntax on
filetype plugin indent on

"Nerdtree
"Auto Strat
"autocmd vimenter * NERDTree
" force start with no files
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif

"Toggle on C-n
map <C-n> :NERDTreeToggle<CR>

"Quit if no tabs
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif


map <C-b> <plug>NERDTreeTabsToggle<CR>

" Markdown 
augroup markdown
    au!
    au BufNewFile,BufRead *.md,*.markdown setlocal filetype=ghmarkdown
augroup END

"augroup crux
"    au WinLeave * set nocursorline nocursorcolumn 
"    au WinEnter * set cursorline cursorcolumn 
"    set cursorline cursorcolumn
"augroup END

map ,c <ESC>:set cursorline cursorcolumn nu<CR>
map ,v <ESC>:set nocursorline nocursorcolumn nonu<CR>

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
"let g:syntastic_puppet_checkers = ['puppetlint']
let g:syntastic_puppet_puppetlint_args = "--no-80chars-check --no-case_without_default-check --no-140chars-check --no-autoloader_layout-check --no-quoted_booleans --no-selector_inside_resource"
let g:syntastic_eruby_ruby_quiet_messages =
    \ {'regex': 'possibly useless use of a variable in void context'}
set expandtab
set tabstop=2
set shiftwidth=2