set nocompatible
filetype plugin indent on
syntax on " enable syntax highlighting
set number relativenumber " relative line numbers
set ai " Sets auto-indentation
set si " Sets smart-indentation
set cursorline " Highlight current cursor line
set tabstop=2 " Tab equal 2 spaces (default 4)
set shiftwidth=2 " Arrow function (>>) creates 2 spaces
set expandtab " Use spaces instead of a tab charater on TAB
set smarttab " Be smart when using tabs
set hlsearch " When searching (/), highlights matches as you go
set incsearch " When searching (/), display results as you type (instead of only upon ENTER)
set smartcase " When searching (/), automatically switch to a case-sensitive search if you use any capital letters
set ttyfast " Boost speed by altering character redraw rates to your terminal
set showmatch " Show matching brackets when text indicator is over them
set noerrorbells " Silence the error bell
set novisualbell " Visually hide the error bell
set encoding=utf8 " Set text encoding as utf8
set clipboard+=unnamedplus " Use the OS clipboard by default
set showtabline=2 " Use tabline
set splitright " split to the right instead of left
set textwidth=80 " Limit to 80 characters in width
set colorcolumn=80 " Colored Column after 80 Characters
set wrap " enable line wrap
set bg=dark " set dark background
set wildmode=longest,list,full
set mouse=a " enable mouse
set splitright " always split right
set viminfo+=n~/.config/vim/viminfo " save viminfo in .vim dir to keep ~/ clean

" Set the runtime path to include Vundle and initialize
set rtp+=~/.config/vim/bundle/Vundle.vim

" Download plug-ins to the ~/.config/vim/plugged/ directory
call vundle#begin('~/.config/vim/plugged')

Plugin 'VundleVim/Vundle.vim'    " Let Vundle manage Vundle
Plugin 'sheerun/vim-polyglot'    " Syntax highlighting
Plugin 'jiangmiao/auto-pairs'    " Pair completion
Plugin 'lervag/vimtex'           " LaTeX tools
Plugin 'vim-airline/vim-airline' " Nicer info line
Plugin 'alvan/vim-closetag'      " Auto close HTML tags
Plugin 'https://github.com/morhetz/gruvbox'         " Color scheme
Plugin 'https://github.com/ap/vim-css-color'        " highlight color codes in their color
Plugin 'https://github.com/907th/vim-auto-save.git' " auto save

call vundle#end()

try
  colorscheme gruvbox
catch
endtry

let g:auto_save = 1
let g:AutoPairsShortcutToggle = '<C-P>' " Press Ctrl+P to disable pair completion
let g:vimtex_view_method = 'zathura'
let g:airline#extensions#tabline#enabled = 1

" jump to last known position when opening a file
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g'\"" | endif

" indent with tab
vnoremap <Tab> >gv
vnoremap <S-Tab> <gv
vnoremap <Tab> >>
nnoremap <Tab> >>
nnoremap <S-Tab> <<

" jump to beginning of selection when exiting visual mode
vnoremap <Esc> o<Esc>

autocmd BufWritePre * %s/\s\+$//e " auto delete trailing white space on save

