"execute pathogen#infect()
set autochdir
set autoindent
set expandtab
set hlsearch
set incsearch
set number
set ruler
set shiftwidth=2
set tabstop=2
set softtabstop=0
set textwidth=79
set signcolumn=yes
set cursorline
set fo-=l fo+=rot
syntax enable

packadd matchit

filetype plugin on
filetype indent on

" Highlighiting fixes to avoid unreadable text
"highlight Folded term=standout ctermfg=3 ctermbg=256
highlight Folded term=standout ctermfg=5 ctermbg=0
highlight SignColumn ctermbg=8
highlight Visual term=reverse ctermbg=7 ctermfg=1 guibg=LightGrey
hi SpellBad term=reverse ctermbg=1 ctermfg=7 gui=undercurl guisp=Red

let g:EditorConfig_max_line_indicator = 'exceeding'
" Diable ALE in-line error highlighting and rely on the markers in the gutter.
highlight clear ALEError
highlight link ALEError NONE

let mapleader=" "

let g:markdown_recommended_style=0
autocmd BufRead,BufNewFile *.md setlocal filetype=markdown fo-=l fo+=ro
autocmd BufRead,BufNewFile *.pco setlocal filetype=chordpro
autocmd BufRead,BufNewFile *.yaml setlocal fo=croqt
autocmd BufRead,BufNewFile *.nim setlocal fo=croqt
autocmd BufRead,BufNewFile *.ts setlocal fo=croqt

" Set/load the view when switching buffers. Used to use to preserve folding.
" Stopped because weirder things were happening.
" autocmd BufEnter *.* silent loadview
" autocmd BufLeave *.* mkview!

autocmd BufRead *.java set foldnestmax=2
autocmd BufRead *.java set foldmethod=syntax

inoremap <Nul> <C-x><C-o>

let g:copilot_filetypes = {
  \ 'nim': v:false,
  \}

" Search for selected text, forwards or backwards.
vnoremap <silent> * :<C-U>
  \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
  \gvy/<C-R><C-R>=substitute(
  \escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
  \gV:call setreg('"', old_reg, old_regtype)<CR>
vnoremap <silent> # :<C-U>
  \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
  \gvy?<C-R><C-R>=substitute(
  \escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
  \gV:call setreg('"', old_reg, old_regtype)<CR>

let g:solarized_contrast="high"
"Highlight lines past 80 characters long
"highlight OverLength ctermbg=red ctermfg=white guibg=#592929
"match OverLength /\%80v.\+/
"autocmd BufAdd .* match OverLength /\%80v.\+/

let g:ale_fixers = {
  \ '*': ['remove_trailing_lines', 'trim_whitespace'],
  \ 'vue': ['prettier'],
  \}
" The following ALE fixer configs have been moved into local RC files (.lvimrc)
"  \ 'javascript': ['deno', 'eslint'],
"  \ 'typescript': ['deno', 'eslint', 'prettier'],


" Disable linters on markdown. I personally don't find any of these useful
" enough to includ in my general authorship. However, ALE performs the check
" for the presence of the executables every time vim enters normal mode. This
" can introduce a noticeable (>1s) lag when running in balanced power mode. So
" I manually disable all of them.
let g:ale_linters = {
  \ 'markdown': [],
  \ 'html': ['HTMLHint', 'proselint', 'write-good'],
  \ 'rst': [],
  \ 'python': ['pylint'],
  \ 'vue': ['prettier'],
  \}
" default (as of time of writing) was:
" \ 'markdown': ['alex', 'cspell', 'languagetool', 'markdownlint', 'mdl', 'proselint', 'redpen', 'remark_lint', 'textlint', 'vale', 'writegood'],

",
let g:ale_fix_on_save = 1
"let g:ale_linters_explicit = 1

let g:ctrlp_max_files = 0
let g:ctrlp_custom_ignore = {
  \ 'dir':  '\v\.git$|\.hg$|\.svn$|\.worktrees$|build$|target$|node_modules$|nimcache$|dist$',
  \ 'file': '\v\.(class|exe|so|dll|sw.)$'
  \ }

let g:ale_virtualtext_cursor = 0
let groovy_space_errors = 1
let groovy_allow_cpp_keywords = 1

cmap w!! w !sudo tee > /dev/null %

let g:tsuquyomi_disable_quickfix = 1
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 0

let g:localvimrc_whitelist = '/home/jdb/projects/probatem/*/.*'

nmap <Leader>wo :vsplit /home/jdbernard/projects/worklog/worklog.txt<CR><C-w>L200<C-w><43<C-w>>
nmap <Leader>ws :w<CR>:silent !git add %<CR>:!git commit<CR>

nmap <Leader>b :CtrlPBuffer<CR>

" Format Biblical quotations in Markdown
vmap <Leader>qb :s/\v\s+(\d+)(\s+\|$)/ **\1**\2/g<CR>

" remove trailing whitespace from all lines
nmap <Leader>ss :%s/\s\+$//<CR>

" check spelling
nmap <Leader>sp :!aspell -c %<CR>

" Execute the current line (stripping leading `$`s)
nmap <Leader>r :.w !sed s/^\\s*[\\$\\#]\\s*//\|bash<CR>

" Execute the current line (stripping leading `$`s) and paste the output into
" the buffer underneath.
nmap <Leader>R yyp!!sed s/^\\s*[\\$\\#]\\s*//\|bash<CR><Esc>

" Execute the selected text as a vim command.
vmap <Leader>e "zy@z<CR>

highlight Folded term=standout ctermfg=3 ctermbg=256

" Use a dark gray for highlighting 'spelling' errors (ALE uses this class for
" highlighting linting errors). Original value was 224
"highlight SpellBad ctermbg=236
"
" Actually, just diable ALE in-line error highlighting and just rely on the
" markers in the gutter.
" highlight clear ALEError
" highlight link ALEError NONE
