
" disable vi compatibility (emulation of old bugs)
set nocompatible

" Select as you type, and make it incrementally
set hlsearch
set incsearch

" use indentation of previous line
set autoindent

" use intelligent indentation for C
set smartindent
set cindent

" configure tabwidth and insert spaces instead of tabs
set tabstop=4        " tab width is 4 spaces
set shiftwidth=4     " indent also with 4 spaces
set softtabstop=4


" turn syntax highlighting on
set t_Co=256
syntax on

colorscheme koehler

" highlight matching braces
set showmatch
set smartcase


" Make sure the history remembers all
set history=1000
set undolevels=1000

" Some nice interactions
set title
set visualbell
set noerrorbells
set nobackup

filetype plugin indent on


" Enhanced keyboard mappings

" switch between header/source with F4
map <S-Tab> :e %:p:s,.h$,.X123X,:s,.cpp$,.h,:s,.X123X$,.cpp,<CR>

set tags+=./tags,tags,~/tags
" recreate tags file with F5
map <F5> :!~/abin/ctags_for_vim ~/tags<CR>

" The 'make_for_vim' is a helper script to allow the proper call of the
" build/clean program.
set makeprg=~/abin/make_for_vim
" build using makeprg with <F7>
map <F7> :make all<CR>
map <S-F7> :make clean<CR>
map <F6> :cn<CR>
map <S-F6> :cp<CR>

hi ColorColumn guibg=#2d2d2d ctermbg=232

" spell settings
:setlocal spell spelllang=en
" set the spellfile - folders must exist
set spellfile=~/.vim/spellfile.add
map <M-Down> ]s
map <M-Up> [s

"Tab navigation shortcuts 

map <C-h> <C-w>h
map <C-l> <C-w>l
map <C-j> <C-w>j
map <C-k> <C-w>k

" NERDTree stuff

nmap <F2> :NERDTreeToggle<CR>

function! GnuIndent()
	setlocal cindent
  	setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1
  	setlocal shiftwidth=2
  	setlocal softtabstop=2
  	setlocal tabstop=8
  	setlocal expandtab " expand tabs to spaces
  	setlocal fo-=ro fo+=cql
endfunction

function! CodingSetTextWidth()
    " wrap lines at 80 chars. 
  setlocal textwidth=80
  setlocal nowrap
  setlocal colorcolumn=80
endfunction

autocmd FileType c,cpp call GnuIndent() 
autocmd FileType c,cpp,java call CodingSetTextWidth() 
autocmd FileType c,cpp,java autocmd BufWritePre <buffer> :%s/\s\+$//e


" Clang Complete Settings
" g:clang_user_options set at vimprj section
let g:clang_use_library=0
let g:clang_user_path='/usr/bin/clang'
let g:clang_complete_copen=0
let g:clang_complete_macros=1
let g:clang_complete_patterns=1
let g:clang_auto_select=1
" Avoids lame path cache generation and other unknown sources for includes 
let g:clang_auto_user_options=".clang_complete"
let g:clang_memory_percent=70

set conceallevel=2
set concealcursor=vin
let g:clang_snippets=0
let g:clang_conceal_snippets=1
" The single one that works with clang_complete
let g:clang_snippets_engine='clang_complete'
"
" Complete options (disable preview scratch window, longest removed to aways
" show menu)
set completeopt=longest,menu

" Limit popup menu height
set pumheight=20


"Complete-T settings

let g:CommandTMatchWindowReverse=1
let g:CommandTMaxHeight=20

set wildignore+=*.o,*.obj,*.d,.git

" From here downwards will be the per system custom part
set wildignore+=*.o,*.obj,*.d,.git,bin,tmp
