set breakindent
set clipboard=unnamedplus
set encoding=utf-8
set expandtab
set hidden
set ignorecase
set listchars=tab:▸\ ,eol:¬
set nocompatible
set nohlsearch
set noshowmode
set relativenumber
set shiftwidth=2
set smartcase
set smarttab
set softtabstop=2
set synmaxcol=150
set tabstop=4
set undofile
set wildmenu

for folder in ['backup', 'swap', 'undo']
    if !isdirectory($XDG_CACHE_HOME . '/nvim/' . folder)
        call mkdir($XDG_CACHE_HOME . '/nvim/' . folder, 'p')
    endif
endfor

set backupdir=$XDG_CACHE_HOME/nvim/backup//
set directory=$XDG_CACHE_HOME/nvim/swap//
set undodir=$XDG_CACHE_HOME/nvim/undo//

filetype plugin on
scriptencoding utf-8
syntax on

" General key mappings
    map <Up> <Nop>
    map <Down> <Nop>
    map <Left> <Nop>
    map <Right> <Nop>

    no <C-k> <C-w>k
    no <C-j> <C-w>j
    no <C-h> <C-w>h
    no <C-l> <C-w>l

    let mapleader = ","

    " Visually select the text that was last edited/pasted
    nmap gV `[v`]

    no ; :

augroup General
    au!
    autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
    autocmd bufwritepost init.vim source $MYVIMRC
augroup END

call has('python3')

if empty(glob($XDG_CONFIG_HOME . '/nvim/autoload/plug.vim'))
    silent !curl -fLo $XDG_CONFIG_HOME/nvim/autoload/plug.vim --create-dirs
        \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

    silent !pip3 install pynvim

    augroup Plug
        au!
        autocmd VimEnter * PlugInstall

        " Bubble single lines with vim-unimpaired
        nmap <C-Up> [e
        nmap <C-Down> ]e

        " Bubble multiple lines with vim-unimpaired
        vmap <C-Up> [egv
        vmap <C-Down> ]egv

        autocmd BufReadPost fugitive://* set bufhidden=delete
    augroup END
endif

call plug#begin($XDG_DATA_HOME . '/nvim/plugged')

Plug '/usr/bin/fzf'
   nnoremap <Leader>fz :call fzf#run({ 'sink': 'e' })<CR>

Plug 'dyng/ctrlsf.vim'
Plug 'godlygeek/tabular'
Plug 'itchyny/lightline.vim'
Plug 'junegunn/goyo.vim'
Plug 'junegunn/limelight.vim'
    let g:limelight_conceal_ctermfg = 'gray'
    autocmd! User GoyoEnter Limelight
    autocmd! User GoyoLeave Limelight!

Plug 'kana/vim-textobj-user'
Plug 'markonm/traces.vim'
Plug 'mbbill/undotree'
    nn <silent> <Leader>u :UndotreeToggle <BAR> :UndotreeFocus<CR>

Plug 'mg979/vim-visual-multi', {'branch': 'master'}
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'preservim/nerdtree'
Plug 'rstacruz/vim-closer'
Plug 'sheerun/vim-polyglot'
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
Plug 'terryma/vim-expand-region'
Plug 'tommcdo/vim-exchange'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'

call plug#end()
