support MacOS
[~madcoder/dotfiles.git] / vimrc
1 " {{{ settings
2
3 set nocompatible                " Use Vim defaults instead of 100% vi compatibility
4 set backspace=indent,eol,start  " more powerful backspacing
5
6 set autoindent                  " always set auto-indenting on
7 set autoread                    " reload unchanged files silentely
8 set clipboard=unnamed           " copy/paste to global clipboard
9 set hidden                      " allow to cycle and hide modified buffers
10 set nobackup                    " Don't keep a backup file
11 set backupcopy=auto,breakhardlink
12 set swapsync=
13 set esckeys                     " allow usage of curs keys within insert mode
14 set timeout
15 set ttimeoutlen=10
16 set timeoutlen=500              " set timout for esc to 50ms
17
18 set listchars=tab:\ \ ,trail:-,extends:>,precedes:<
19 set list
20 set joinspaces                  " insert two spaces after a period with every joining of lines.
21                                 " This is very nice!
22 set lazyredraw                  " [VIM5];  do not update screen while executing macros
23 set ttyfast
24 set magic                       " Use some magic in search patterns?  Certainly!
25 set modeline                    " Allow the last line to be a modeline - useful when
26                                 " the last line in sig gives the preferred text-width
27                                 " for replies.
28 set modelines=5
29 set pastetoggle=<F4>
30
31 set nonumber
32 set report=0                    " show a report when N lines were changed.
33                                 " report=0 thus means "show all changes"!
34
35 set laststatus=2                " show status line?  Yes, always!
36 set noruler                       " show cursor position?  Yep!
37 set statusline=[\ %f%m\ %r%y\ %=\ hex:%B\ \ %l,%c%V\ \ %P\ ]
38
39 set shiftwidth=4                " Number of spaces to use for each insertion of
40                                 " (auto)indent.
41 set shortmess=at                " Kind of messages to show.   Abbreviate them all!
42                                 " New since vim-5.0v: flag 'I' to suppress "intro message".
43 set scrolloff=2                 " context
44 set showcmd                     " Show current uncompleted command?  Absolutely!
45 set showmatch                   " Show the matching bracket for the last ')'?
46 set showmode                    " Show the current mode?  YEEEEEEEEESSSSSSSSSSS!
47
48 set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc,.cmi,.cmo
49                                 " Suffixes to ignore in file completion
50
51 set tabstop=8                   " tabstop
52 set softtabstop=4               " sts
53 set expandtab                   " expand tabs
54 set notextmode                  " no - I am using Vim on UNIX!
55 set textwidth=0                 " Don't wrap words by default
56 set cc=+1
57 set title                       " Permet de voir le tit. du doc. crt. ds les XTERM
58 set viminfo='1000,/1000,:1000,<1000,@1000,n~/.viminfo
59 set history=1000
60                                 " What info to store from an editing session
61                                 " in the viminfo file;  can be used at next session.
62 set undofile
63 set undodir=~/.cache/vim/
64 au BufWritePre /tmp/* setlocal noundofile
65 set sessionoptions=buffers,folds,localoptions,options,tabpages,help
66
67 set ignorecase                  " Do case insensitive matching
68 set incsearch                   " Incremental search
69 set hlsearch                    " hilight search
70
71
72 set whichwrap=<,>,[,]           "
73 set wildchar=<TAB>              " the char used for "expansion" on the command line
74                                 " default value is "<C-E>" but I prefer the tab key:
75 set wildmenu                    " Completion on the command line shows a menu
76 set wildmode=longest,full
77 set winminheight=0              " Minimum height of VIM's windows opened
78 set mouse=a
79 set mousefocus
80 set wrapmargin=1
81 set nowritebackup
82 set foldmethod=marker
83
84 set noequalalways
85 set eadirection=
86
87 set cpoptions-=C                " enable commands that continue on the next line
88
89 " use ctrl-n ctrl-n instead of ctrl-x ctrl-k
90 set complete-=k complete+=k
91
92 set tags=tags;/,.tags;/,TAGS;/
93
94 set cinoptions=
95 set cinoptions+=L0.5s          " align labels at 0.5 shiftwidth
96 set cinoptions+=:0.5s,=0.5s    " same for case labels and code following a label
97 set cinoptions+=g0.5s,h0.5s    " same for c++ stuff
98 set cinoptions+=t0             " type on the line before the functions is not idented
99 set cinoptions+=(0,Ws          " indent in functions ( ... ) when it breaks
100 set cinoptions+=m1             " aligh the closing ) properly
101 set cinoptions+=j1             " java/javscript -> fixes blocks
102 "set cinoptions+=l0.5s          " align code after label ignoring braces.
103
104 set diffopt=filler,context:5,iwhite
105 set fillchars+=diff:\ ,vert:│
106
107 set makeprg=LC_ALL=C\ make\ MONOCHROME=1
108 set grepprg=egrep\ --exclude='*.blk.c'\ --exclude='*.blkk.cc'\ -n\ $*\ /dev/null
109
110 exe "set path=." . system("echo | cpp -v 2>&1 | grep '^ .*/include' | tr -d \"\n\" | tr \" \" \",\"")
111 set path+=.;/
112
113 " }}}
114 " {{{ vim 7 settings
115
116 if version >= 700
117     set autochdir              " autochdir...
118     set virtualedit=onemore    " Yes I want to be able to be "on \n"
119     set spelllang=en_us,fr
120     set pumheight=16
121
122     " make <enter> work in popup
123     inoremap <cr> <C-R>=pumvisible() ? "\<lt>C-Y>" : "\<lt>cr>"<cr>
124 else
125     au BufEnter * :lcd %:p:h
126 endif
127
128 " }}}
129 " {{{ Window magic
130
131 function! DeleteBuffer()
132    let bid = bufnr("%")
133    bnext
134    exe "bdel " . bid
135    redraw
136 endfunction
137
138 map <C-W>d :call DeleteBuffer()<cr>
139 "map <C-W>k :bd<cr>
140 map <C-W>g :bo cw 8<cr>
141
142 " }}}
143 " {{{ Mappings
144
145 " {{{ Tab Key magic ...
146 vmap <tab> >gv
147 vmap <bs> <gv
148
149 function! TabAlign()
150     let col  = col('.')
151     let lnum = line('.')
152
153     while lnum > 1
154         let lnum = lnum - 1
155         let ln = strpart(getline(lnum), col-1)
156         let ms = matchstr(ln, '[^ ]*  *[^ ]')
157         if ms != ""
158             break
159         endif
160     endwhile
161
162     if lnum == 1
163         return "\<Tab>"
164     else
165         let @z = substitute(strpart(ms, 0, strlen(ms)-1), '.', ' ', 'g')
166         if col > strlen(getline('.'))
167             return "\<C-O>\"zp"
168         else
169             return "\<C-O>\"zP"
170         endif
171     endif
172
173 endfunction
174
175 function! CleverTab()
176     let c = strpart(getline('.'), col('.')-2, 1)
177     if c == ' ' || c == '\t' || c == ''
178         return TabAlign()
179     else
180         return "\<C-P>"
181     endif
182 endfunction
183 inoremap <Tab> <C-R>=CleverTab()<CR>
184 inoremap <S-Tab> <C-R>=TabAlign()<CR>
185
186 " }}}
187
188 map + :cnext<cr>
189 map - :cprevious<cr>
190 map <kPlus> :cnext<cr>
191 map <kMinus> :cprevious<cr>
192
193 map Q gq
194
195 noremap  <F2>   :set mouse=a<cr>
196 noremap  <F3>   :set mouse=h<cr>
197 noremap  <F5>   :source ~/.vimrc<cr>
198
199 inoremap <F6>   <c-o>mzviwU`z
200 noremap  <F7>   :set ai!<CR>:set ai?<cr>
201 inoremap <F7>   <space><esc><F7>a<bs>
202
203 noremap  <F11>  :make!<cr>:bo cw 8<cr><cr>
204 inoremap <F11>  <esc>:make!<cr>:bo cw 8<cr><cr>
205 noremap  <S-F11> :make clean<cr><cr>
206 inoremap <S-F11> <esc>:make clean<cr><cr>
207
208 " }}}
209 "{{{ FTYPES
210
211 if has("autocmd")
212     filetype plugin indent on
213     syntax on
214
215     au Syntax {cpp,c,javascript} runtime syntax/doxygen.vim
216
217     au BufReadPost *
218                 \ if line("'\"") > 0 && line("'\"") <= line("$") |
219                 \   exe "normal g`\"" |
220                 \ endif
221
222     au VimLeave * mksession! ~/.cache/session.vim
223
224     au FileType debchangelog normal zO
225
226     au FileType asciidoc setlocal tw=78 noet ts=8 sw=8
227     au FileType javascript setlocal cindent tw=78 iskeyword+=$
228     au FileType actionscript setlocal cindent tw=78 iskeyword+=$ noignorecase ff=dos
229     au FileType mail setlocal noet iskeyword+=- tw=72
230
231     au FileType haxe setlocal tw=78 noignorecase cin ai
232     au FileType d,c,cpp setlocal tw=78 noignorecase "fo-=ro
233     au FileType ocaml,acute,omlet setlocal sw=2 sts=2 tw=78
234     au FileType php  setlocal et fo+=ro tw=78 indentexpr= cin
235     au FileType python setlocal foldmethod=indent foldnestmax=1
236
237     au FileType diff   setlocal nofoldenable
238
239     au FileType html,xhtml,xml setlocal sw=2
240     au FileType mail setlocal spell
241
242     " make error list special
243     au BufRead quickfix setlocal nobuflisted nowrap number
244
245     au FileType svn setlocal spell tw=76
246     au FileType git setlocal spell tw=76
247
248     au BufRead,BufNewFile */dev/scm/git/* setlocal noet sw=8
249
250     let ocaml_noindent_let=1
251     let git_diff_spawn_mode=2
252     let git_diff_opts = "--no-renames --summary -C -M"
253     let c_gnu=1
254     let c_space_errors=1
255     let c_no_curly_error=1
256
257     let g:bufExplorerFindActive=0
258     let g:bufExplorerSplitOutPathName=1
259     let g:bufExplorerShowRelativePath=0
260     let g:bufExplorerSortBy='fullpath'
261
262     let g:is_bash=1
263     let g:sh_fold_enabled=1
264
265     let g:debchangelog_fold_enable = 1
266     let g:debcontrol_fold_enable = 1
267 endif " has ("autocmd")
268
269 " }}}
270 " {{{ PLUGINS
271
272 runtime macros/matchit.vim
273 "runtime macros/justify.vim
274
275 runtime ftplugin/man.vim
276 nmap ! :exe "Man" expand("<cword>")<cr>
277
278 " }}}
279 " {{{ COLORS, GUI and FOLDING
280
281 set background=light
282 hi clear
283 if exists("syntax_on")
284    syntax reset
285 endif
286
287 if has("gui_running")
288     set guioptions=eit
289     set guifont=terminus
290     set guicursor=a:blinkon0
291     set background=light
292
293     fun! GuiTabLabel()
294         let label = ''
295         let bufnrlist = tabpagebuflist(v:lnum)
296
297         " Append the number of windows in the tab page if more than one
298         let wincount = tabpagewinnr(v:lnum, '$')
299         let label .= wincount
300
301         " Add '[*]' if one of the buffers in the tab page is modified
302         for bufnr in bufnrlist
303             if getbufvar(bufnr, "&modified")
304                 let label .= '[*]'
305                 break
306             endif
307         endfor
308
309
310         if exists("t:tabname")
311             return t:tabname . ': ' . label
312         else
313             return label . '[' . bufname(bufnrlist[tabpagewinnr(v:lnum) - 1]) .']'
314         endif
315     endf
316     set guitablabel=%{GuiTabLabel()}
317 endif
318
319 fun! <SID>Y(a)
320     if strlen(a:a) != 6 || a:a == "yellow"
321         return a:a
322     endif
323     if has("gui_running")
324         return "#".a:a
325     endif
326     let l:r = ("0x" . strpart(a:a, 0, 2)) + 0
327     let l:g = ("0x" . strpart(a:a, 2, 2)) + 0
328     let l:b = ("0x" . strpart(a:a, 4, 2)) + 0
329     if &t_Co == 88
330         let l:gray  = 10
331         let l:cube  = 4
332         let l:shift = 79
333     else
334         let l:gray  = 26
335         let l:cube  = 6
336         let l:shift = 232
337     endif
338
339     if l:r * l:gray / 256 == l:g * l:gray / 256 && l:r * l:gray / 256 == l:b * l:gray / 256
340         let l:s = l:r * l:gray / 256
341         if l:s == 0
342             return "black"
343         elseif l:s == l:gray - 1
344             return "white"
345         else
346             return l:shift + l:s
347         endif
348     endif
349     let l:x = ((l:r * l:cube) / 256)
350     let l:y = ((l:g * l:cube) / 256)
351     let l:z = ((l:b * l:cube) / 256)
352     return 16 + ((l:x * l:cube + l:y) * l:cube) + l:z
353 endfun
354
355 fun! <SID>myhi(cls, m, fg, bg)
356     if has("gui_running")
357         exec "hi ".a:cls." gui=".a:m." guifg=".<SID>Y(a:fg)." guibg=".<SID>Y(a:bg)
358     else
359         exec "hi ".a:cls." cterm=".a:m." ctermfg=".<SID>Y(a:fg)." ctermbg=".<SID>Y(a:bg)
360     endif
361 endfun
362
363 if has("gui_running") || &t_Co >= 88
364     if has("gui_running")
365         exec <SID>myhi("Normal",       "none",       "dfdfdf",    "00000f")
366         exec <SID>myhi("MoreMsg",      "none",       "dfdfdf",    "00000f")
367     else
368         exec <SID>myhi("Normal",       "none",       "dfdfdf",    "NONE")
369         exec <SID>myhi("MoreMsg",      "none",       "dfdfdf",    "NONE")
370     endif
371     exec <SID>myhi("ColorColumn",  "none",       "NONE",      "0f0f0f")
372     exec <SID>myhi("Comment",      "none",       "afafff",    "0f0f0f")
373     exec <SID>myhi("Folded",       "none",       "afafff",    "0f0f0f")
374
375     exec <SID>myhi("SpecialKey",   "none",       "dfdfdf",    "0f0f0f")
376     exec <SID>myhi("Todo",         "underline",  "yellow",    "2f2f2f")
377     exec <SID>myhi("Error",        "bold",       "white",     "red")
378
379     exec <SID>myhi("Function",     "none",       "4fdfdf",    "NONE")
380     exec <SID>myhi("Identifier",   "none",       "4fdfdf",    "NONE")
381
382     exec <SID>myhi("Cursor",       "reverse",    "dfdfdf",    "black")
383     exec <SID>myhi("Visual",       "none",       "NONE",      "2f2f2f")
384     exec <SID>myhi("IncSearch",    "none",       "black",     "yellow")
385     exec <SID>myhi("Search",       "none",       "black",     "yellow")
386
387     exec <SID>myhi("StatusLine",   "none",       "yellow",    "2f2f2f")
388     exec <SID>myhi("StatusLineNc", "none",       "dfdfdf",    "1c1c1c")
389     exec <SID>myhi("WildMenu",     "none",       "white",     "0f0f0f")
390     exec <SID>myhi("VertSplit",    "none",       "darkgray",  "0f0f0f")
391     exec <SID>myhi("NonText",      "none",       "darkgray",  "NONE")
392
393     exec <SID>myhi("MatchParen",   "none",       "white",     "0f0f0f")
394     exec <SID>myhi("Pmenu",        "none",       "dfdfdf",    "0f0f0f")
395     exec <SID>myhi("PmenuSel",     "none",       "white",     "3f3f7f")
396     exec <SID>myhi("PmenuSbar",    "none",       "white",     "0f0f0f")
397     exec <SID>myhi("PmenuThumb",   "none",       "3f3f7f",    "3f3f7f")
398
399     exec <SID>myhi("SpellBad",     "none",       "NONE",      "800000")
400     exec <SID>myhi("SpellCap",     "none",       "NONE",      "004000")
401     exec <SID>myhi("SpellLocal",   "none",       "NONE",      "004000")
402     exec <SID>myhi("SpellRare",    "none",       "NONE",      "NONE")
403
404     exec <SID>myhi("Label",        "none",       "bf7f00",    "NONE")
405     exec <SID>myhi("Conditional",  "none",       "bf7f00",    "NONE")
406     exec <SID>myhi("Repeat",       "none",       "bf7f00",    "NONE")
407     exec <SID>myhi("Statement",    "none",       "bf7f00",    "NONE")
408
409     exec <SID>myhi("StorageClass", "none",       "20b020",    "NONE")
410     exec <SID>myhi("Type",         "none",       "20b020",    "NONE")
411     exec <SID>myhi("Structure",    "none",       "20b020",    "NONE")
412     exec <SID>myhi("Directory",    "none",       "20b020",    "NONE")
413
414     exec <SID>myhi("Include",      "none",       "bf0fbf",    "NONE")
415     exec <SID>myhi("PreProc",      "none",       "bf0fbf",    "NONE")
416     exec <SID>myhi("Macro",        "none",       "bf0fbf",    "NONE")
417     exec <SID>myhi("SpecialChar",  "none",       "bf0fbf",    "NONE")
418
419     exec <SID>myhi("Character",    "none",       "bf0f0f",    "NONE")
420     exec <SID>myhi("String",       "none",       "bf0f0f",    "NONE")
421     exec <SID>myhi("Constant",     "none",       "bf0f0f",    "NONE")
422
423     " diff
424     exec <SID>myhi("DiffAdd",      "none",       "NONE",      "002f0f")
425     exec <SID>myhi("DiffDelete",   "none",       "NONE",      "2f000f")
426     exec <SID>myhi("DiffChange",   "none",       "NONE",      "00003f")
427     exec <SID>myhi("DiffText",     "underline",  "NONE",      "00003f")
428     exec <SID>myhi("diffRemoved",  "none",       "bf0fbf",    "NONE")
429
430     " C
431     exec <SID>myhi("cFunction",    "none",       "b0b0b0",    "NONE")
432
433     " Doxygen
434     if !exists(':SynLink')
435         command -nargs=+ SynLink hi def link <args>
436     endif
437     SynLink doxygenSpecialTypeOnelineDesc  doxygenBrief
438     SynLink doxygenSpecialOnelineDesc      doxygenBrief
439     SynLink doxygenSpecialHeading          doxygenBrief
440     SynLink doxygenParamDirection          doxygenSpecial
441
442     exec <SID>myhi("javaScriptTpl",    "none",       "7fcf7f",    "none")
443     exec <SID>myhi("javaScriptTplMark","none",       "b218b2",    "none")
444     exec <SID>myhi("doxygenComment",   "none",       "6060ff",    "0f0f0f")
445     exec <SID>myhi("doxygenBrief",     "none",       "6060ff",    "0f0f0f")
446     exec <SID>myhi("doxygenPrev",      "none",       "6060ff",    "0f0f0f")
447     exec <SID>myhi("doxygenParam",     "none",       "6060ff",    "0f0f0f")
448     exec <SID>myhi("doxygenSpecial",   "none",       "6060ff",    "0f0f0f")
449     exec <SID>myhi("doxygenParamName", "underline",  "6060ff",    "0f0f0f")
450 else
451     hi Comment      cterm=none       ctermfg=blue       ctermbg=none
452     hi Folded       cterm=none       ctermfg=brown      ctermbg=none
453
454     hi Visual       cterm=reverse    ctermfg=none       ctermbg=none
455     hi IncSearch    cterm=underline  ctermfg=white      ctermbg=none
456     hi Search       cterm=underline  ctermfg=white      ctermbg=none
457
458     hi StatusLine   cterm=none       ctermfg=white      ctermbg=blue
459     hi StatusLineNc cterm=none       ctermfg=black      ctermbg=white
460     hi WildMenu     cterm=none       ctermfg=white      ctermbg=none
461     hi VertSplit    cterm=none       ctermfg=darkgray   ctermbg=none
462     hi NonText      cterm=none       ctermfg=darkgray   ctermbg=none
463
464     hi MatchParen   cterm=underline  ctermfg=none       ctermbg=none
465     hi Pmenu        cterm=none       ctermfg=gray       ctermbg=black
466     hi PmenuSel     cterm=none       ctermfg=black      ctermbg=gray
467     hi PmenuSbar    cterm=none       ctermfg=blue       ctermbg=blue
468     hi PmenuThumb   cterm=none       ctermfg=gray       ctermbg=gray
469
470     hi SpellBad     cterm=underline  ctermfg=lightred   ctermbg=none
471     hi SpellCap     cterm=none       ctermfg=lightred   ctermbg=none
472     hi SpellLocal   cterm=underline  ctermfg=darkgreen  ctermbg=none
473     hi SpellRare    cterm=none       ctermfg=none       ctermbg=none
474 endif
475
476 " Custom
477 hi def link htmlTag htmlStatement
478 hi def link htmlEndTag htmlStatement
479
480 ia <buffer> sabine Sabine
481 " }}}