" Smart indent and and better tab length
set formatoptions-=cro
set tabstop=3 softtabstop=3
set shiftwidth=3
set expandtab
set smartindent

set nu
set relativenumber
set nohlsearch
set hidden
set incsearch
set scrolloff=8
set colorcolumn=100
set signcolumn=yes

" Remove arrow keys to train my fingers
noremap <Up>   <Nop>
noremap <Down>   <Nop>
noremap <Left>   <Nop>
noremap <Right>   <Nop>

" set <leader> to space
nnoremap <space> <nop>
let mapleader=" "

call plug#begin('~/.vim/plugged')
" Syntax highlighting and autocomplete for nvim
Plug 'neoclide/coc.nvim', {'branch': 'release'}

" FZF for better file jumping.
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

" Theme and Syntax Highlighting
Plug 'morhetz/gruvbox'
Plug 's3rvac/vim-syntax-yara'
call plug#end()

" Set colorscheme
let g:gruvbox_contrast_dark = 'hard'

" Transparent background with gruvbox theme
colorscheme gruvbox
set background=dark
hi Normal guibg=NONE ctermbg=NONE

" Setup yara syntax highlighting
autocmd BufNewFile,BufRead *.yar,*.yara setlocal filetype=yara

" FZF key bindings 
nnoremap <leader>ff <cmd>Files<cr>
nnoremap <leader>fg <cmd>Rg<cr>
nnoremap <leader>fb <cmd>Buffers<cr>

" use <tab> for trigger completion and navigate to the next complete item
function! CheckBackspace() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

inoremap <silent><expr> <Tab>
      \ coc#pum#visible() ? coc#pum#next(1) :
      \ CheckBackspace() ? "\<Tab>" :
      \ coc#refresh()

inoremap <expr> <Tab> coc#pum#visible() ? coc#pum#next(1) : "\<Tab>"
inoremap <expr> <S-Tab> coc#pum#visible() ? coc#pum#prev(1) : "\<S-Tab>"
