set number
set colorcolumn=88
set background=dark
set cursorline
set shell=/bin/sh
syntax on

au BufNewFile,BufRead *.go set tabstop=4 softtabstop=4 shiftwidth=4
			\ expandtab autoindent fileformat=unix
au BufNewFile,BufRead *.toml set tabstop=4 softtabstop=4 shiftwidth=4
			\ expandtab autoindent fileformat=unix
au BufNewFile,BufRead *.yaml set tabstop=2 softtabstop=2 shiftwidth=2
			\ expandtab autoindent fileformat=unix
au BufNewFile,BufRead *.html,*.css set tabstop=2 softtabstop=2 shiftwidth=2
			\ expandtab autoindent colorcolumn=0
au BufNewFile,BufRead *.launch set filetype=xml
autocmd FileType debcontrol :set colorcolumn=80 textwidth=80
augroup py
	autocmd FileType python :set tabstop=4 softtabstop=4 shiftwidth=4 expandtab autoindent fileformat=unix
	autocmd FileType python nnoremap <F9> :Black<CR> :Isort <CR>
augroup end
augroup terraform
	autocmd FileType terraform :set tabstop=2 softtabstop=2 shiftwidth=2 expandtab autoindent fileformat=unix
	autocmd FileType terraform nnoremap <F9> :! terraform fmt<CR>
augroup end
augroup go
	autocmd FileType go :set tabstop=4 softtabstop=4 shiftwidth=4 expandtab autoindent fileformat=unix
	au FileType go nmap <F9> <Plug>(go-fmt)<Plug>(go-lint)
	au FileType go nmap <F7> <Plug>(go-build)
	au FileType go nmap <F8> <Plug>(go-run)
    au FileType go nmap gd <Plug>(go-def)
augroup end
augroup sh
	autocmd FileType sh :set tabstop=2 softtabstop=2 shiftwidth=2 expandtab autoindent fileformat=unix
augroup end

" vim-plug
" :PlugInstall to install new one
call plug#begin('~/.vim/plugged')
Plug 'dense-analysis/ale'
Plug 'Valloric/YouCompleteMe'
" enhanced search
Plug 'junegunn/vim-slash' 
Plug 'preservim/nerdtree'
Plug 'vim-airline/vim-airline'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'luochen1990/rainbow'
Plug 'psf/black', {'branch': 'main'}
Plug 'fisadev/vim-isort'
Plug 'jvirtanen/vim-hcl' " HCL files used by terraform
Plug 'hashivim/vim-terraform'
" show git diff in sign column
Plug 'airblade/vim-gitgutter'
" Themes
Plug 'sainnhe/sonokai'
" Language specific
Plug 'vim-python/python-syntax'
Plug 'wgwoods/vim-systemd-syntax'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'cespare/vim-toml',{ 'branch': 'main' }
call plug#end()

" Theme
if has('termguicolors')
	let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
  let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
	set termguicolors
endif
let g:sonokai_style = 'atlantis'
let g:sonokai_disable_italic_comment = 1
colorscheme sonokai
let g:airline_theme = 'sonokai'

" Ale
let g:ale_linters = {'python': ['pylint', 'mypy'],}
let g:ale_fixers = {'python': ['black', 'isort']}
let g:ale_python_pylint_options = '--disable=C0111,C0330'
let g:ale_python_mypy_options = '--ignore-missing-imports --disallow-untyped-defs --disallow-incomplete-defs'

" Black
let g:black_linelength = 88

" ycm
let g:ycm_autoclose_preview_window_after_insertion = 1
let g:ycm_autoclose_preview_window_after_completion = 1

" isort
let g:vim_isort_python_version = 'python3'
let g:vim_isort_config_overrides = {'profile': 'black'}

" NERDTREE
" open nerdtree when no file is specified on startup
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
" toggle nerdtree keyboard shortcut
map <C-t> :NERDTreeToggle<CR>

" RAINBOW_PARENTHESES
"au FileType c,cpp,py call rainbow#load()

" python syntax
let g:python_highlight_all = 1
let g:python_highlight_func_calls = 0

" enable rainbow brackets
let g:rainbow_active = 1

" vim-go
let g:go_def_mapping_enabled = 0

" terraform
let g:terraform_fmt_on_save = 1
let g:terraform_align = 1

"underline spell errors in terminals
hi SpellBad ctermfg=218 cterm=underline
