set runtimepath+=~/.config/vim,~/.config/vim/after
set viminfo+=n~/.cache/viminfo

set number relativenumber

let mapleader = " "

augroup numbertoggle
  autocmd!
  autocmd WinEnter * set relativenumber
  autocmd WinLeave * set norelativenumber
augroup END

syntax on

set tabstop=4
set shiftwidth=4
set expandtab

set modeline

set encoding=utf-8

set nowrap

autocmd FileType yaml setlocal ai ts=2 sw=2 et cuc nu

runtime ftplugin/man.vim
set keywordprg=:Man

if has("autocmd")
    " Save cursor position. I don't understand this part
    au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif

    au FileType lilypond au BufWritePost * !lilypond %
endif


" Plug plugins using VimPlug
call plug#begin('~/.config/vim/plugged')
    Plug 'editorconfig/editorconfig-vim'
    Plug 'airblade/vim-gitgutter'
    Plug 'samoshkin/vim-mergetool'
    Plug 'fidian/hexmode'
    Plug 'scrooloose/nerdtree'
    Plug 'itchyny/lightline.vim'
    Plug 'nanotech/jellybeans.vim'
    Plug 'scrooloose/syntastic'
    Plug 'sersorrel/vim-lilypond'
    Plug 'vim-scripts/DoxygenToolkit.vim'
    Plug 'drmikehenry/vim-headerguard'
    Plug 'cespare/vim-toml'
call plug#end()

map <leader>m :Magit<CR>
map <leader>n :NERDTreeToggle<CR>

autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

set laststatus=2
let g:lightline = {
\   'active': {
\       'left': [
\           [ 'mode', 'paste' ],
\           [ 'readonly', 'filename', 'modified', 'gitbranch' ]
\       ],
\       'right': [
\           [ 'percent', 'lineinfo' ],
\           [ 'fileformat', 'fileencoding', 'filetype', 'synthastic' ],
\           [ 'charvaluehex' ]
\       ]
\   },
\   'component': {
\       'charvaluehex': '0x%B',
\   },
\   'component_function': {
\       'synthastic': 'SyntasticStatuslineFlag',
\       'gitbranch': 'fugitive#head'
\   },
\ }

if has('termguicolors') && &termguicolors
    let g:jellybeans_overrides['background']['guibg'] = 'none'
endif
let g:jellybeans_overrides = {
\   'Todo': {
\       'guifg': '303030',
\       'guibg': 'f0f000',
\       'ctermfg': 'Black',
\       'ctermbg': 'Yellow',
\       'attr': 'bold'
\   },
\   'Comment': { 'guifg': 'cccccc' },
\   'LineNr': { 'guifg': 'aaaaaa' },
\   'background': {
\       'ctermbg': 'none',
\       '256ctermbg': 'none'
\   },
\ }
colorscheme jellybeans

let g:syntastic_always_populate_loc_list = 0
let g:syntastic_auto_loc_list = 0
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_oclint_config_file = '.syntastic_oclint_config'
let g:syntastic_c_config_file = '.syntastic_cc_config'