let plug_install = 0
let autoload_plug_path = stdpath('config') . '/autoload/plug.vim'

if !filereadable(autoload_plug_path)
    silent exe '!curl -fL --create-dirs -o ' . autoload_plug_path .
     \ ' https://raw.github.com/junegunn/vim-plug/master/plug.vim'
    execute 'source ' . fnameescape(autoload_plug_path)
    let plug_install = 1
endif
unlet autoload_plug_path

call plug#begin('~/.config/nvim/plugins')

" Code development helpers {{{
Plug 'neovim/nvim-lspconfig'
Plug 'p00f/clangd_extensions.nvim'
"Plug 'ray-x/lsp_signature.nvim'
Plug 'matsui54/denops-signature_help'
Plug 'RRethy/vim-illuminate'
Plug 'mizlan/iswap.nvim'

"Plug 'dbeniamine/cheat.sh-vim'
"Plug 'puremourning/vimspector'
"Plug 'vim-test/vim-test'
Plug 'lukas-reineke/indent-blankline.nvim'
Plug 'liuchengxu/vista.vim'
Plug 'ggandor/leap.nvim'

Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-treesitter/playground'
Plug 'p00f/nvim-ts-rainbow'
Plug 'nvim-treesitter/nvim-treesitter-textobjects'
Plug 'romgrk/nvim-treesitter-context'

Plug 'cdelledonne/vim-cmake'

Plug 'andymass/vim-matchup'
Plug 'folke/which-key.nvim'
Plug 'numToStr/Comment.nvim'
Plug 'danymat/neogen'
" }}}

" Completion {{{
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/cmp-calc'
Plug 'joshzcold/cmp-jenkinsfile'
Plug 'petertriho/cmp-git'
Plug 'mstanciu552/cmp-matlab'
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
Plug 'quangnguyen30192/cmp-nvim-ultisnips'
" }}}

" Files switch, jump and grep-like tools {{{
Plug 'kyazdani42/nvim-web-devicons'
Plug 'kyazdani42/nvim-tree.lua'
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'fhill2/telescope-ultisnips.nvim'
Plug 'stevearc/dressing.nvim'
Plug 'MunifTanjim/nui.nvim'
Plug 'inside/vim-search-pulse'
Plug 'wellle/targets.vim'
Plug 'numToStr/FTerm.nvim'
" }}}

" Git integration {{{
Plug 'tpope/vim-fugitive'
Plug 'APZelos/blamer.nvim'
Plug 'lewis6991/gitsigns.nvim'
" }}}

" Support for random filetypes {{{
"Plug 'weirongxu/plantuml-previewer.vim' |
Plug 'kergoth/vim-bitbake' " Bitbake templates and syntax
Plug 'aklt/plantuml-syntax'
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']}
"Plug 'vim-pandoc/vim-pandoc'
Plug 'chrisbra/csv.vim'
" }}}

" Other plugins (external tools, etc) {{{
"Plug 'MortenStabenau/matlab-vim'
"Plug 'junegunn/goyo.vim'
Plug 'lukas-reineke/virt-column.nvim'
"Plug 'glacambre/firenvim'
"Plug 'JMcKiern/vim-shoot'
"Plug 'protex/better-digraphs.nvim'
" }}}

" Note taking {{{
Plug 'vimwiki/vimwiki'
Plug 'michal-h21/vimwiki-sync'
"Plug 'michal-h21/vim-zettel'
" }}}

" Colorschemes {{{
Plug 'vim-airline/vim-airline' | Plug 'vim-airline/vim-airline-themes'
"Plug 'jaredgorski/spacecamp'
"Plug 'lifepillar/vim-gruvbox8'
"Plug 'dylanaraps/wal'
"Plug 'tanvirtin/monokai.nvim'
"Plug 'marko-cerovac/material.nvim'
" }}}

" Testing phase {{{
Plug 'nvim-neorg/neorg'
Plug 'jubnzv/virtual-types.nvim'
Plug 'https://gitlab.com/yorickpeterse/nvim-window.git'
Plug 'themercorp/themer.lua'
Plug 'mfussenegger/nvim-dap'
Plug 'mizlan/iswap.nvim'
Plug 'wuelnerdotexe/vim-enfocado'
Plug 'frabjous/knap'
Plug 'kevinhwang91/nvim-ufo' | Plug 'kevinhwang91/promise-async'
Plug 'kaiuri/nvim-mariana'
Plug 'ziontee113/icon-picker.nvim'
Plug 'Saecki/crates.nvim'
" }}}

call plug#end()

set termguicolors
set shell=bash

if plug_install
    PlugInstall --sync
endif
unlet plug_install

set number
set clipboard+=unnamedplus

set noshowmode
set laststatus=2

lua << EOF
require("virt-column").setup { }
EOF
set colorcolumn=80

set background=dark
"Wal scheme:
"colorscheme wal
"Material scheme:
"let g:material_style = "deep ocean"
"colorscheme material

colorscheme enfocado

"highlight MatchParen cterm=underline ctermbg=black ctermfg=NONE
"highlight VirtColumn ctermfg=DarkGrey ctermbg=NONE
set listchars=tab:▸\ ,trail:¬
set list
"hi clear SpellBad
"hi SpellBad cterm=underline

set tabstop=2
set shiftwidth=2
set softtabstop=2

set expandtab

set ignorecase
set smartcase

set gdefault

set textwidth=80
set formatoptions+=t
set scrolloff=10
set nowrap
set sidescroll=5

set inccommand="split"

set lazyredraw

" space one line, home,end globally increase/decrease
nnoremap <Home> zc
nnoremap <End> zo

" Ctags {{{
if isdirectory($HOME . '/.cache/nvim/tags') == 0
	:silent !mkdir -p ~/.cache/nvim/tags > /dev/null 2>&1
endif
let g:gutentags_cache_dir='~/.cache/nvim/tags'
"let g:gutentags_ctags_extra_args=['--fields=+l']

if isdirectory($HOME . '/.cache/nvim/undo') == 0
    :silent !mkdir -p ~/.cache/nvim/undo > /dev/null 2>&1
endif
set undodir=~/.cache/nvim/undo/
set undofile

"let mapleader = "\\"
nmap <space> <leader>

tnoremap <ESC><ESC> <C-\><C-n>

inoremap jj <ESC>
inoremap jk <ESC>
"inoremap :w<CR> <Esc>:w<CR>
nnoremap Q <cmd>q

" Reselect visual block after incrementing/decrementing
vnoremap <c-a> <c-a>gv
vnoremap <c-x> <c-x>gv

nnoremap <leader>2 <esc>:set tabstop=2 softtabstop=2 shiftwidth=2<cr>
nnoremap <leader>4 <esc>:set tabstop=4 softtabstop=4 shiftwidth=4<cr>
nnoremap <leader>8 <esc>:set tabstop=8 softtabstop=8 shiftwidth=8<cr>

nnoremap <leader><space> :nohlsearch<cr>

" TextEdit might fail if hidden is not set.
set hidden

" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup

" New dynamic window height
set cmdheight=0

" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300

" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
set shortmess-=F

set signcolumn=number

set wildmode=longest,list,full

match Error /\s\+$\|DU\cPA/

setglobal virtualedit=block
setglobal shiftround

let g:vimwiki_list = [{'path': '~/vimwiki/',
                      \ 'syntax': 'markdown', 'ext': '.md'}]

let g:blamer_enabled = 1
let g:blamer_show_in_insert_modes = 0
let g:blamer_template = '<committer> <committer-time> <summary>'
let g:blamer_date_format = '%Y-%m-%d'
let g:blamer_relative_time = 0
"highlight Blamer guifg=lightgrey

"packadd termdebug

""""""""""""""""""
"  gui settings  "
""""""""""""""""""
set guifont=IBM\ Plex\ Mono\ Text:h8
let g:neovide_cursor_vfx_mode = "pixiedust"
