packadd minpac
call minpac#init()
" minpac must have {'type': 'opt'} so that it can be loaded with `packadd`.
call minpac#add('k-takata/minpac', {'type': 'opt'})
call minpac#add('honza/vim-snippets', {'type': 'start'})
call minpac#add('junegunn/limelight.vim')
call minpac#add('junegunn/goyo.vim')
call minpac#add('ambv/black')
call minpac#add('davidhalter/jedi-vim')
call minpac#add('vim-airline/vim-airline')
call minpac#add('ap/vim-css-color')
call minpac#add('fatih/vim-go')
call minpac#add('dpelle/vim-Grammalecte')
call minpac#add('ledger/vim-ledger')
call minpac#add('tpope/vim-markdown')
call minpac#add('nfnty/vim-nftables')
call minpac#add('adborden/vim-notmuch-address')
call minpac#add('cespare/vim-toml')
call minpac#add('pbrisbin/vim-mkdir')
call minpac#add('tpope/vim-eunuch')

command! PackUpdate call minpac#update()
command! PackClean call minpac#clean()

let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
let g:limelight_conceal_ctermfg = 'gray'
let mapleader=","
set backup
set backupdir=$HOME/.vim/backup
set hidden
set ignorecase
set lcs:tab:>-,trail:.
set list
set modeline
set number
set showmatch
set spelllang=fr
set statusline+=%#warningmsg#
set statusline+=%*
set undofile
set undodir=~/.vim/undo
"set virtualedit=all
"set clipboard=unnamed
set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
"set formatoptions=tcrqn2w
"set formatlistpat=^\\s*[\\d\\*-]\\+[\\]:.)}\\t\ ]\\s*

highlight clear SpellBad
highlight SpellBad term=standout ctermfg=1 term=underline cterm=underline
highlight clear SpellCap
highlight SpellCap term=standout ctermfg=3 term=underline cterm=underline
highlight clear SpellRare
highlight SpellRare term=underline cterm=underline
highlight clear SpellLocal
highlight SpellLocal term=underline cterm=underline
highlight RedundantSpaces ctermbg=red guibg=red
match RedundantSpaces /\s\+$\| \+\ze\t\|\t/

" Jump to the last position when reopening a file
if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

map <silent> <F7> "<Esc>:silent setlocal spell! spelllang=fr<CR>"
map <silent> <F8> "<Esc>:silent setlocal spell! spelllang=en<CR>"
map <F9> <esc>:!hugo server -Dw<CR>
map ,ga :!git add -p<cr>
map ,gA :!git add %<cr>
map ,gf :!git add
map ,gs :!git status<cr>
map ,gc :!git commit -m ""<left>
map ,gC :!git add %<cr>:!git commit -m ""<left>
map ,gd :!git diff<cr>
map ,gD :!git diff --cached<cr>
map ,gp :!git push<cr>
map ,gP :!git pull<cr>
map ,gb :!git branch<cr>
map ,gB :!git branch
map ,gh :!git checkout
map ,gi :!git init<cr>
map ,gt :!tig<cr>
map <A-Left> :bp<cr>  " Alt + Left arrow goes to the previous buffer
map <A-Right> :bn<cr>  " Alt + Right arrow goes to the next buffer

function! s:goyo_enter()
  let b:quitting = 0
  let b:quitting_bang = 0
  autocmd QuitPre <buffer> let b:quitting = 1
  cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
endfunction

function! s:goyo_leave()
  " Quit Vim if this is the only remaining buffer
  if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
    if b:quitting_bang
      qa!
    else
      qa
    endif
  endif
endfunction

autocmd! User GoyoEnter call <SID>goyo_enter()
autocmd! User GoyoLeave call <SID>goyo_leave()

{{- if eq .chezmoi.osRelease.prettyName "Debian GNU/Linux 10 (buster)" }}
let g:go_version_warning = 0
{{- end }}

{{- if eq .chezmoi.hostname "taupo" }}
map <F5> <esc>:!pdflatex %<CR>
map <F6> <esc>:!pinpoint %<CR>
map <F9> <esc>:!hugo server -Dw<CR>
map ,b  :!bash gen.sh<cr><cr>
map ,c  <esc>2GddOTo: contact@sysnove.fr<esc>jddOCc: <esc>
autocmd BufNewFile,BufRead *.hledger,*.ledger,*.journal setfiletype ledger
autocmd Filetype ledger set nospell
{{- end }}
