source ~/.config/nvim/plugged/plug.vim

set nocompatible
filetype plugin indent on
syntax enable
set encoding=utf-8
set number relativenumber
set numberwidth=4
set tabstop=4 shiftwidth=4 expandtab smartindent
set incsearch hlsearch ignorecase smartcase
set wrap
set mouse=a
set scrolloff=5
set cursorline
set noshowmode
set shortmess+=I
set autoindent

set statusline=%#StatusLineMode#
set statusline+=\ %{ModeName()}
set statusline+=%#StatusLine#
set statusline+=\ %f\ %m\ %r\ %y
set statusline+=%=
set statusline+=\ Ln:%l/%L\ Col:%c\ \[%p%%]

hi Normal guibg=NONE ctermbg=NONE guifg=#dcdfe4 ctermfg=245
hi NormalNC guibg=NONE ctermbg=NONE guifg=#b0b3b8 ctermfg=245
hi LineNr guibg=NONE ctermbg=NONE guifg=#a6a8ab ctermfg=245
hi CursorLine guibg=#3c3f41 ctermbg=59 guifg=NONE ctermfg=NONE
hi VertSplit guibg=NONE ctermbg=NONE guifg=#a6a8ab ctermfg=245
hi StatusLine guibg=#3c3f41 guifg=#dcdfe4 ctermbg=59 ctermfg=245
hi StatusLineMode guibg=#d85e5e guifg=#ffffff ctermbg=196 ctermfg=15 gui=bold
hi Visual guibg=#4a545c guifg=NONE ctermbg=67 ctermfg=67
hi VisualNOS guibg=#4a545c guifg=NONE ctermbg=67 ctermfg=67
hi VisualSB guibg=#4a545c guifg=NONE ctermbg=67 ctermfg=67
hi Search guibg=NONE ctermbg=NONE guifg=#5c8cba ctermfg=66
hi IncSearch guibg=NONE ctermbg=NONE guifg=#7fb3c8 ctermfg=32
hi Pmenu guibg=NONE ctermbg=NONE guifg=#dcdfe4 ctermfg=245
hi PmenuSel guibg=NONE ctermbg=NONE guifg=#3c3f41 ctermbg=59
hi WildMenu guibg=NONE ctermbg=NONE guifg=#5c8cba ctermfg=66
hi Folded guibg=NONE ctermbg=NONE guifg=#a6a8ab ctermfg=245
hi SignColumn guibg=NONE ctermbg=NONE guifg=#b0b3b8 ctermfg=245

hi StatusLine guibg=#5c2f2f guifg=#ffffff ctermbg=88 ctermfg=15
hi StatusLineMode guibg=#5c2f2f guifg=#ffffff ctermbg=88 ctermfg=15 gui=bold
hi LineNr guibg=NONE ctermbg=NONE guifg=#5c2f2f ctermfg=88
hi CursorLine guibg=#5c2f2f ctermbg=88 guifg=NONE ctermfg=NONE
hi VertSplit guibg=NONE ctermbg=NONE guifg=#5c2f2f ctermfg=88
hi Error guibg=NONE ctermbg=NONE guifg=#ff6c6b ctermfg=167
hi Warning guibg=NONE ctermbg=NONE guifg=#e0af68 ctermfg=180

autocmd VimEnter * if $USER == "root" | highlight Normal guibg=#5c2f2f guifg=#ffffff | endif

function! ModeName()
let modeval = mode()
return modeval ==# 'n'   ? 'NML '  :
\ modeval ==# 'i'   ? 'INT '  :
\ modeval ==# 'v'   ? 'VSL '  :
\ modeval ==# 'V'   ? 'VLI '  :
\ modeval ==# "\<C-v>" ? 'VBL ' :
\ modeval ==# 'R'   ? 'RPL ' :
\ modeval ==# 'c'   ? 'CMD ' :
\ 'UNKNOWN'
endfunction

let mapleader = "\<Space>"
nnoremap <leader>w \:w<CR>
nnoremap <leader>q \:q<CR>
nnoremap <silent> <leader>h \:nohlsearch<CR>
nnoremap <leader>n \:set relativenumber!<CR>
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
nnoremap <leader>cd :Ex<CR>

map j gj
map k gk

set termguicolors
set list
set listchars=

set backupdir=~/.cache/nvim/backup
set directory=~/.cache/nvim/swap
set undodir=~/.cache/nvim/undo
set undofile
set wrapscan
set shortmess+=c
set autoread
set cmdheight=1
set belloff=all
set laststatus=2
set smoothscroll
set scrolljump=3
set hidden
set splitbelow
set splitright
set nobackup
set nowritebackup
set lazyredraw

call plug#begin('~/.config/nvim/plugged')
Plug 'tpope/vim-sensible'
Plug 'junegunn/fzf.vim'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'jiangmiao/auto-pairs'
Plug 'tpope/vim-repeat'
Plug 'mattn/emmet-vim'
Plug 'norcalli/nvim-colorizer.lua'
Plug 'nvim-treesitter/nvim-treesitter-textobjects'
Plug 'nvim-treesitter/nvim-treesitter-refactor'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
call plug#end()

lua << EOF
require'colorizer'.setup()
EOF

lua << EOF
local parsers = require'nvim-treesitter.parsers'.get_parser_configs()
local ensure_installed = {}

for lang, _ in pairs(parsers) do
  if lang ~= "verilog" and lang ~= "ipkg" and lang ~= "gdshader" and
     lang ~= "latex" and lang ~= "swift" and lang ~= "mlir" and
     lang ~= "ocamllex" and lang ~= "unison" and lang ~= "teal" and
     lang ~= "scfg" then
    table.insert(ensure_installed, lang)
  end
end

require'nvim-treesitter.configs'.setup {
  ensure_installed = ensure_installed,
  highlight = {
    enable = true,
    additional_vim_regex_highlighting = false,
  },
  indent = {
    enable = true,
  },
}
EOF
