set nocompatible              " be iMproved, required

if has('win32') || has ('win64')
    let $VIMHOME = $HOME."/vimfiles"

    set backupdir=$TEMP//
    set directory=$TEMP//
else
    let $VIMHOME = $HOME."/.vim"
endif

let g:vimtex_view_method = 'mupdf'
let g:vimtex_latexmk_options = '-pdf -pdflatex="xelatex -synctex=1 \%S \%O" -verbose -file-line-error -interaction=nonstopmode'
set mouse=a

let g:tmpl_search_paths = [ $VIMHOME.'/templates' ]

call plug#begin($VIMHOME.'/plugged')
    Plug 'terryma/vim-multiple-cursors'
    Plug 'thinca/vim-localrc'
    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'
    Plug 'rafi/awesome-vim-colorschemes'
    Plug 'lervag/vimtex'
    Plug 'ctrlpvim/ctrlp.vim'
    Plug 'tpope/vim-surround'
    Plug 'airblade/vim-gitgutter'
    Plug 'tpope/vim-commentary'
    Plug 'tibabit/vim-templates'
    Plug 'Shougo/deoplete.nvim'
    Plug 'roxma/nvim-yarp'
    Plug 'roxma/vim-hug-neovim-rpc'

    " load local plugins
    if filereadable("~/.local-plugins.vimrc")
        source "~/.local-plugins.vimrc" 
    endif
call plug#end()

set colorcolumn=80,120
set t_Co=256

"
" My own config
"

" one time settings
if !exists("g:running")
"     " Conemu specific settings
"     if !has('gui_running') && !has('nvim')
"         set term=xterm

"         inoremap <Char-0x07F> <BS>
"         nnoremap <Char-0x07F> <BS>
        
"         let &t_AB="\e[48;5;%dm"
"         let &t_AF="\e[38;5;%dm"

"         inoremap <Esc>[62~ <C-X><C-E>
"         inoremap <Esc>[63~ <C-X><C-Y>
"         nnoremap <Esc>[62~ <C-E>
"         nnoremap <Esc>[63~ <C-Y>
"     endif

    if has('gui_running')
        set guifont=Fira_Code_Medium:h9:cANSI:qDRAFT
        set guioptions=

        set columns=200
        set lines=58
        
        colorscheme tender
    endif
endif

let g:running = 1

" UTF-8 support
if has("multi_byte")
  if &termencoding == ""
    let &termencoding = &encoding
  endif
  set enc=utf-8
  set encoding=utf-8
  setglobal fileencoding=utf-8
  " setglobal bomb
  " set fileencodings=ucs-bom,utf-8,latin1
endif

" i like to have ctrl-x menu
set shortmess-=c

" Required for operations modifying multiple buffers like rename.
set hidden
set splitbelow
set shellslash

" set backspace=2
set autoindent

" tabs
set expandtab
set tabstop=4
set shiftwidth=4

" syntax
syntax on
set number

" disable bells
set noeb vb t_vb=
    
let &t_SI = "\<Esc>[6 q"
let &t_SR = "\<Esc>[6 q"
let &t_EI = "\<Esc>[2 q"

" filetypes
" autocmd FileType c,cpp :compiler cl
au FileType asm :set ft=masm
au FileType tex :set tw=120

" airline
let g:airline_powerline_fonts = 1
let g:airline_theme = "tender"
let g:airline#extensions#tabline#enabled = 1

" ctrlp
let g:ctrlp_switch_buffer = 'Et'

" ycm config
let g:ycm_confirm_extra_conf = 0

" no arrows
nnoremap <Left> <Nop>
nnoremap <Right> <Nop>
nnoremap <Up> <Nop>
nnoremap <Down> <Nop>

set completeopt=longest,menuone

" remapings
nnoremap YY :%y+<CR>

nnoremap <space><cr> :nohlsearch<cr>

noremap <space>y "*y
noremap <space>Y "*Y
noremap <space>p "*p
noremap <space>P "*P

nnoremap <c-s-tab> gT
nnoremap <c-tab> gt

nnoremap <space>a ggVG

vnoremap > >gv
vnoremap < <gv

command! SetCwd :cd %:p:h

nnoremap <F6> :SetCwd<CR>

map <F5> :set rnu!<CR>
map <C-F5> :source ~/.vimrc<CR>

vnoremap gO "py<Esc>:e <C-R>p<CR>
vnoremap gT "py<Esc>:tabe <C-R>p<CR>

nmap \\ :CtrlP<CR>

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