set background=dark                                                                    " Dark theme for the colorscheme
colorscheme hybrid                                                                     " Colorscheme

set ruler                                                                              " Show the cursor position all the time
set cursorline                                                                         " Highlight current line
set number relativenumber                                                              " Line numbers, current and relative

set updatetime=100                                                                     " Shorten update time to 100ms instead of 4

set listchars=tab:▸·,trail:-,nbsp:·
set list                                                                               " Display tabs and trailing spaces
set linebreak                                                                          " Break lines with wrap on word separators
set breakindent                                                                        " Indent the wrapped line
set breakindentopt=shift:2,sbr                                                         " Indent by 2 and draw the break char
set showbreak=↳
highlight Normal ctermbg=NONE guibg=NONE                                               " transparent background
highlight EndOfBuffer ctermbg=NONE
highlight List ctermbg=NONE ctermfg=darkred guibg=lightgray                            " Listchars highlight
match List /\%xa0/
2match List / \+$/

highlight DiffText ctermbg=104 ctermfg=220
highlight LineNr ctermfg=darkgrey
highlight Comment cterm=italic                                                         " Comments in italics
highlight MatchParen ctermbg = 11                                                      " Match parenthesis in bright yellow
highlight Conceal ctermbg=NONE ctermfg=grey
highlight Visual ctermbg=darkgrey
highlight Pmenu ctermbg=darkgrey

set showcmd                                                                            " Show visual selection size

set splitright                                                                         " Vertical split to the right
set fillchars=vert:⎢                                                                   " Vertical line for splits

set laststatus=2                                                                       " Always display status bar

set timeoutlen=300                                                                     " Set key timeout

set hidden                                                                             " Enable buffers to be hidden even if modified

set fileencoding=utf-8                                                                 " Encoding
scriptencoding utf-8

set autochdir                                                                          " Auto change directory to current file

set undofile undodir=~/.config/nvim/undodir/                                           " Permanent undo
set backup backupdir=~/.config/nvim/backupdir                                          " Set backup folder
set swapfile directory=~/.config/nvim/swap                                             " Swapfile
set updatecount=10                                                                     " Write to swap every 10 chars

set foldmethod=syntax                                                                  " Fold with syntax
set foldlevelstart=99

set completeopt=noinsert,menuone                                                       " Display a completion menu, don't insert anything till selected

set wildmenu                                                                           " Autocomplete in command mode
set wildmode=list:longest,full                                                         " First show list of matches without replacing, then completion
set wildignore+=*.bmp,*.gif,*.ico,*.jpg,*.png,*.ico                                    " Skip those filetypes and directories
set wildignore+=*.mkv,*.mp4,*.avi
set wildignore+=.cache/*,Private/*,Documents/*,Downloads/*,Jeux/*,node_modules/*,old_desktop/*,R/*
set wildignorecase                                                                     " Ignore case when searching for files

set cpoptions+=$                                                                       " Display $ in change mode
set backspace=indent,eol,start                                                         " Allow backspace to erase indent,eol, before start

set history=50                                                                         " Keep 50 lines of command line history

set gdefault                                                                           " s///g by default
set incsearch                                                                          " Do incremental searching
set hlsearch                                                                           " Highlight searches
set ignorecase smartcase                                                               " Smartcase
set inccommand=nosplit                                                                 " Preview replace
highlight Search cterm=bold,underline ctermfg=NONE ctermbg=NONE                        " Search results in underlined bold

set spelllang=en_us                                                                    " Correct spelling in English by default

set mouse=a                                                                            " Enable mouse

set autoindent                                                                         " Indent like previous line
set smartindent                                                                        " Also indent in code blocks

set scrolloff=10                                                                       " Vertical scroll offset
set sidescroll=1                                                                       " Scroll horizontally one line at a time
set sidescrolloff=1000                                                                 " Horizontal scroll offset (keep cursor in middle)

set expandtab                                                                          " Use spaces instead of tabs
set tabstop=2                                                                          " Use 2 spaces for one tab
set softtabstop=2                                                                      " Use 2 spaces for soft tabs
set shiftwidth=2                                                                       " Shift by 2 spaces when indenting

set formatoptions+=j                                                                   " Delete comment character when joining comment lines
set diffopt=filler,vertical,foldcolumn:0,iwhiteall
set clipboard^=unnamed,unnamedplus                                                     "default clipboard to X clipboard

set diffopt=filler,vertical

augroup Resource
  autocmd!

  autocmd! bufwritepost ~/.config/nvim/init.*
        \ source ~/.config/nvim/init.vim                                                 " Reload .vimrc after editing
augroup END

augroup templates
  autocmd!

  autocmd! BufNewFile *.md 0r ~/.config/nvim/templates/template.md
  autocmd! BufNewFile *.Rmd 0r ~/.config/nvim/templates/template.Rmd
augroup END

augroup ncm2start
  autocmd!

  autocmd! BufEnter * call ncm2#enable_for_buffer()
augroup END
