set nocompatible

"
" Basics
"

set number
set ruler
syntax on

" Set encoding
set encoding=utf-8

" Whitespace stuff
set nowrap
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
set list listchars=tab:\ \ ,trail:·

" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase

" Tab completion
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*

" Status bar
set laststatus=2

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

" Show (partial) command in the status line
set showcmd

" Remember last location in file
if has("autocmd")
  au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
    \| exe "normal g'\"" | endif
endif

"
" File Type Config
"

" make uses real tabs
au FileType make set noexpandtab

" Thorfile, Rakefile, Vagrantfile and Gemfile are Ruby
au BufRead,BufNewFile {Gemfile,Rakefile,Vagrantfile,Thorfile,config.ru}    set ft=ruby

" make Python follow PEP8 ( http://www.python.org/dev/peps/pep-0008/ )
au FileType python set softtabstop=4 tabstop=4 shiftwidth=4 textwidth=79

" snes syntax highlighting
au BufNewFile,BufRead *.asm,*.s set filetype=snes"

" load the plugin and indent settings for the detected filetype
filetype plugin indent on
filetype plugin on
set omnifunc=syntaxcomplete#Complete

" Directories for swp files
set backupdir=~/.vim/.backup
set directory=~/.vim/.backup

" Include local vimrc
if filereadable(expand("~/.vimrc.local"))
  source ~/.vimrc.local
endif

"
" Tool Configs
"

" CTags
map <Leader>rt :!ctags --extra=+f -R *<CR><CR>
map <C-\> :tnext<CR>

" Opens an edit command with the path of the currently edited file filled in
" Normal mode: <Leader>e
map <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>

" Opens a tab edit command with the path of the currently edited file filled in
" Normal mode: <Leader>t
map <Leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR>

" % to bounce from do to end etc.
runtime! macros/matchit.vim

" Dank Mono Italics
highlight Keyword cterm=italic

" FZF config
set rtp+=/usr/local/opt/fzf

" Inserts the path of the currently edited file into a command
noremap <C-P> :FZF <CR>

" ALE config
let g:ale_linters = {'javascript': ['eslint']}

"
" A E S T H E T I C S
"

" Color Column
let &colorcolumn="80,150"

" Default color scheme
set termguicolors
color rbdr

" Map colors to vim colors
let g:fzf_colors =
\ { 'fg':      ['fg', 'Normal'],
  \ 'bg':      ['bg', 'Normal'],
  \ 'hl':      ['fg', 'Comment'],
  \ 'fg+':     ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
  \ 'bg+':     ['bg', 'CursorLine', 'CursorColumn'],
  \ 'hl+':     ['fg', 'Statement'],
  \ 'info':    ['fg', 'PreProc'],
  \ 'border':  ['fg', 'Ignore'],
  \ 'prompt':  ['fg', 'Conditional'],
  \ 'pointer': ['fg', 'Exception'],
  \ 'marker':  ['fg', 'Keyword'],
  \ 'spinner': ['fg', 'Label'],
  \ 'header':  ['fg', 'Comment'] }

"
" Editing Shortcuts
"

" Folding Settings
set foldmethod=syntax
set foldnestmax=10
set nofoldenable
set foldlevel=1

" Relative numbers
autocmd FocusLost * :set norelativenumber
autocmd InsertEnter * :set norelativenumber
autocmd InsertLeave * :set relativenumber
autocmd CursorMoved * :set relativenumber

function! NumberToggle()
  if(&relativenumber == 1)
    set norelativenumber
  else
    set relativenumber
  endif
endfunction

nnoremap <C-n> :call NumberToggle()<cr>


" Move things up and down using Ctrl + Shift
nnoremap <C-S-j> :m .+1<CR>==
nnoremap <C-S-k> :m .-2<CR>==
inoremap <C-S-j> <Esc>:m .+1<CR>==gi
inoremap <C-S-k> <Esc>:m .-2<CR>==gi
vnoremap <C-S-j> :m '>+1<CR>gv=gv
vnoremap <C-S-k> :m '<-2<CR>gv=gv

"
" Plug Config
"

call plug#begin('~/.vim/plugged')

" Syntaxes
Plug 'rbdr/api-notation.vim'
Plug 'elzr/vim-json'
Plug 'mustache/vim-mode'
Plug 'othree/yajs.vim'
Plug 'ARM9/snes-syntax-vim'
Plug 'posva/vim-vue'
Plug 'leafOfTree/vim-svelte-plugin'
Plug 'bumaociyuan/vim-swift'
Plug 'udalov/kotlin-vim'

" Editing
Plug 'jiangmiao/auto-pairs'
Plug 'tpope/vim-endwise'
Plug 'michaeljsmith/vim-indent-object'

" Tools
Plug 'editorconfig/editorconfig-vim'
Plug 'dense-analysis/ale'
Plug 'vim-scripts/LargeFile'
Plug 'tpope/vim-fugitive'
Plug 'milkypostman/vim-togglelist'
Plug 'jremmen/vim-ripgrep'
Plug 'lifepillar/vim-mucomplete'

" List ends here. Plugins become visible to Vim after this call.
call plug#end()