set nocompatible

so ~/.config/nvim/plugins.vim
so ~/.config/nvim/word_processing.vim

" --Plugin Configurations
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 1
let g:airline_theme='base16_bespin'
let g:formatdef_gunk = '"gunk format -"'
let g:formatters_gunk = ['gunk']
let g:go_go_fmt_command="gopls"
let g:go_gopls_enabled = 1
let g:go_gopls_gofumpt=1
let g:pandoc#command#autoexec_command = "Pandoc! pdf --citeproc"
let g:pandoc#formatting#mode = 'ha'
let g:pandoc#formatting#textwidth = 100
let g:pandoc#spell#enabled = 0
let g:svelte_indent_script = 0
let g:svelte_indent_style = 0

"--My ColorScheme
set background=dark
set termguicolors
let g:srcery_italic=1
let g:srcery_bold=1
let g:srcery_white='#FCE8C3'
let g:srcery_bright_white='#FCF5E8'

colorscheme srcery

" General
set noerrorbells
set title
set number
set relativenumber
set signcolumn=number
set ruler
set wrap
set scrolloff=3
set clipboard+=unnamedplus
set colorcolumn=81
set guicursor+=a:blinkon0
set nofoldenable
set updatetime=300
set shortmess+=c
set mouse=a

" Indentation and highlighting
filetype on
filetype plugin on
filetype plugin indent on
filetype indent on
set shiftwidth=4
set tabstop=4
set softtabstop=0

" Searchstuff
set ignorecase
set smartcase
set incsearch
set hlsearch

" Purple comments and transparent background
hi Comment guifg=#b799bd ctermfg=102
hi Normal guibg=#NONE ctermbg=NONE

set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}

lua <<EOF
-- animated scrolling
require'neoscroll'.setup {
	mappings = {'<C-u>', '<C-d>'},
	hide_cursor = true,
	stop_eof = true,
	use_local_scrolloff = false,
	respect_scrolloff = false,
	cursor_scrolls_alone = true,
	easing_function = nil,
	pre_hook = nil,
	post_hook = nil,
	}

-- better syntax highlighting
require'nvim-treesitter.configs'.setup {
	highlight = { enable = true },
	incremental_selection = { enable = true },
	textobjects = { enable = true },
	}
EOF

""""""""""""""""""""""""""""""""""""""""
"                                      "
"               KEYBINDS               "
"                                      "
""""""""""""""""""""""""""""""""""""""""

inoremap jj <Esc>
noremap // :nohls<RETURN>
noremap ; :
command WQ wq
command Wq q
command W w
command Q w

nnoremap <C-k> :bprev<CR>
nnoremap <C-j> :bnext<CR>
inoremap <C-k> <Esc>:bprev<CR>
inoremap <C-j> <Esc>:bnext<CR>
nnoremap gf :e <cfile>

noremap <Up> <Nop>
noremap <Right> <Nop>

inoremap <C-P> <C-\><C-O>:call CocActionAsync('showSignatureHelp')<CR>
noremap <silent> <Left> :call CocAction('diagnosticNext')<CR>
noremap <silent> <Down> :call CocAction('diagnosticPrevious')<CR>
nnoremap <silent> K :call <SID>show_documentation()<CR>

let mapleader=","

nnoremap <leader>w :e<SPACE>
nnoremap <leader>E :Files<CR>
nnoremap <leader>b :Buffers<CR>
nnoremap <leader>d :bp<cr>:bd #<cr>

nmap <leader>a <Plug>(coc-codeaction-selected)
noremap <leader>y :VCopy<CR>
vnoremap <leader>y :<BS><BS><BS><BS><BS>VCopyVisual<CR>
noremap <leader>pd :Pandoc pdf --citeproc -Vmainfont="TeX Gyre Schola"
			\ -Vmathfont="TeX Gyre Schola Math" -Vdocumentclass="scrartcl"
			\ --resource-path=images --highlight-style ~/.config/pandoc/code.theme
			\ -Fpandoc-crossref -Fpandoc-include -Fpantable <CR>

nnoremap <leader>g :GoRun<CR>
nnoremap <leader>f :PrettierAsync<CR>
nnoremap <leader>so :so ~/.config/nvim/init.vim<CR>
nnoremap <leader>e :CocCommand explorer --toggle<CR>

noremap <A-j> dap } p
noremap <A-k> vap :m '<-2<CR>gv=gv

" COC
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
nmap <leader>rn <Plug>(coc-rename)
nnoremap <leader>o  :<C-u>CocList outline<cr>

""""""""""""""""""""""""""""""""""""""""
"                                      "
"              FILE TYPES              "
"                                      "
""""""""""""""""""""""""""""""""""""""""


autocmd FileType html,css,scss
			\ setlocal ts=4 sts=4 sw=4 expandtab
autocmd FileType javascript,typescript,typescriptreact,svelte
			\ setlocal ts=2 sts=2 sw=2 expandtab
autocmd BufNewFile,BufRead *.markdown,*.text
			\ setlocal ts=2 sts=2 sw=2 textwidth=100 colorcolumn=101
autocmd FileType sql
			\setlocal ts=2 sts=2 sw=2 expandtab
autocmd BufNewFile,BufRead *.md.tmpl
			\ setlocal filetype=markdown
autocmd BufNewFile,BufRead .*config,*.config,config
			\ setlocal filetype=gitconfig
autocmd BufNewFile,BufRead *.bolt
			\ setlocal filetype=typescript
autocmd BufNewFile,BufRead *.cql
			\ setlocal filetype=cql
autocmd BufNewFile,BufRead *.gradle,*.groovy
			\ setlocal filetype=groovy
autocmd BufNewFile,BufRead *.osgjs,*.osgjs.gz
			\ setlocal filetype=json
autocmd BufNewFile,BufRead *.postcss
			\ setlocal filetype=css
autocmd BufNewFile,BufRead *.go.tpl,*.peg,*.qtpl
			\ setlocal syntax=go
autocmd BufNewFile,BufRead *.gunk
			\ setlocal filetype=gunk syntax=go
autocmd BufNewFile,BufRead *.gltf
			\ setlocal filetype=gltf syntax=json
autocmd BufNewFile,BufRead *.frag
			\ setlocal filetype=glsl syntax=glsl
autocmd BufWrite *.gunk
			\ :Autoformat

let g:coc_snippet_next = '<tab>'
let g:coc_snippetnext = '<tab>'
autocmd CursorHold * silent call CocActionAsync('highlight')

inoremap <silent><expr> <TAB>
			\ pumvisible() ? coc#_select_confirm() :
			\ coc#expandableOrJumpable() ?
			\ "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
			\ <SID>check_back_space() ? "\<TAB>" :
			\ coc#refresh()
function! s:check_back_space() abort
	let col = col('.') - 1
	return !col || getline('.')[col - 1]  =~# '\s'
endfunction


inoremap <silent><expr> <c-space> coc#refresh()

inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
			\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

function! s:show_documentation()
	if (index(['vim','help'], &filetype) >= 0)
		execute 'h '.expand('<cword>')
	elseif (coc#rpc#ready())
		call CocActionAsync('doHover')
	else
		execute '!' . &keywordprg . " " . expand('<cword>')
	endif
endfunction

function! s:doHover()
	if coc#rpc#ready()
		let diagnostics = CocAction('diagnosticList')
		if empty(diagnostics)
			call CocActionAsync('doHover')
			return
		endif
		let file = expand('%:p')
		let lnum = line('.')
		let cnum = col('.')
		for v in diagnostics
			if v['file'] != file
						\ || lnum != v['lnum']
						\ || cnum < v['location']['range']['start']['character']
						\ || cnum > v['location']['range']['end']['character']
				call CocActionAsync('doHover')
				return
			endif
		endfor
	endif
endfunction

augroup mygroup
	autocmd!
	" Setup formatexpr specified filetype(s).
	autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
	" Update signature help on jump placeholder.
	autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end

