"  _ _|_|_____ ___ ___
" | | | |     |  _|  _|
"  \_/|_|_|_|_|_| |___|


" Menu:
" 1...................Plugins
" 2....................Basics
" 3................Remappings
" 4......Plugin Configuration
" 3.......................GUI
" 4................Statusline
" 5.....................Fonts
" 6....................Panels
" 7................MS Windows


"set laststatus=2
"set showtabline=2

" -----[ PLUGINS ]----- "

call plug#begin('~/.vim/plugged')
    Plug 'itchyny/lightline.vim'                            " simple, goodlooking statusline
    Plug 'junegunn/fzf.vim'                                 " fuzzy finder for files/buffers ..
    Plug 'ervandew/supertab'                                " tabcompletion
    Plug 'junegunn/goyo.vim'                                " Goyo, distraction free writing for LaTeX
    Plug 'HansMartin/inline-python'                         " Inline Python exec.
    Plug 'airblade/vim-rooter'                              " root-directory finder
    Plug 'dylanaraps/wal.vim'                               " Set coloscheme from pywal
    Plug 'rust-lang/rust.vim'                               " For Rust
    Plug 'preservim/nerdtree'                               " Not sure if needed
    Plug 'tpope/vim-fugitive'                               " Git for Vim
call plug#end()


" -----[ BASICS ]----- "

" Color Settings
colorscheme wal             " using the wal colorscheme
set mouse=a                 " for moving splits with the mouse

" Encoding
set encoding=utf-8          " set UTF-8 Encoding per Defautl (render glyphs and co)
set nocompatible
set conceallevel=0          " conceallevel for markdown/latex files

" disable any (terminal-)bells
set noeb
set novb
set belloff=all

" Path settings
set backupdir=$HOME/.config/nvim/backups
set noswapfile
set undodir=$HOME/.config/nvim/undo

" Syntax and Lines
syntax enable
set number
set relativenumber
filetype plugin indent on

" CursorLine
" set cursorline
" hi CursorLine term=none cterm=none

" Tab/Spacing settings
set expandtab               " use spaces instead of tabs
set shiftwidth=4            " number of columns when indenting with > or <
set softtabstop=4           " number of spaces when hitting tab
set autoindent              " set indentation from previous line

" searching...
set ignorecase              " case insensitive
set nohlsearch              " no search highlighting after the search is done
set noshowmatch             " disable that blinking bracket stuff
set wildmenu                " shows menu for tab completion
set incsearch               " search if you type the letters
set path+=**                " include all subdirs for finding files (eg. :find)
set backspace=2
set scrolloff=2


" -----[ Remappings ]----- "

" Bind 'n' to nzz (center current line)
nnoremap n nzz
nnoremap N Nzz


" Jump 5 lines at once with Ctr+e and Ctr+y
nnoremap <C-e> 5<C-e>
nnoremap <C-y> 5<C-y>

" mapping for fast buffer switching
nnoremap <leader>a :bp!<CR>
noremap <leader>s :bn!<CR>

" When selecting Text, keep the Block selected
vmap < <gv
vmap > >gv


" Remove Trailling Whitespaces on Buffer Write
autocmd BufWritePre * :%s/\s\+$//e

" auto execute xrdb when .Xresources is saved
autocmd BufWritePost ~/.Xresources !xrdb %

" automatically adjust splits
autocmd VimResized * wincmd =

" use Ctr+C for Copy Pasterino into sys. clipboard
vnoremap <C-c> "*y :let @+=@*<CR>
nnoremap <leader>c "+yy


" Bind Goyo to shortcut
map <F3> <ESC>:Goyo <CR>



" Markdown viewer script
map <F9> <ESC>:silent !md-viewer % <CR>
" Auto make
map <F8> <ESC>:silent !make <CR>

" -----[ Plugin Configuration ]----- "

" Lightline - Status Line

" To use the wombat colorscheme
set noshowmode " no required when having lightline in place
let g:lightline = {
      \ 'colorscheme': 'wombat',
      \ }

" FZF - Best Tool ever
nnoremap <C-t> :Tags<CR>
nnoremap <C-b> :Buffers<CR>
nnoremap <C-n> :Files<CR>

" Nerdtree (tmp replacement with Vifm
nnoremap <C-t> :NERDTreeToggle<CR>

" Map the Python Evaluation into the vim-expression command(Q)
nnoremap Q :EvalPython <CR>
let g:il_append=1
let g:il_use_nextline=0


" UltiSnips (Ancient, but could come in handy at some day)
"let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsExpandTrigger = '<c-s>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
let g:UltiSnipsSnippetsDir='~/.vim/UltiSnips/'


" Goyo Configuration

let g:goyo_width=100
let g:goyo_height=100


" --- LaTeX Mappings ---
"     stolen from Luke Smith's vimrc "
"     will only work in .tex files
" Navigating with guides
autocmd FileType tex inoremap <Space><Tab> <Esc>/<++><Enter>"_c4l
autocmd FileType tex vnoremap <Space><Tab> <Esc>/<++><Enter>"_c4l
autocmd FileType tex nnoremap <Space><Tab> <Esc>/<++><Enter>"_c4l

" Compile document using xelatex:
autocmd FileType tex inoremap <F5> <Esc>:!pdflatex<space><c-r>%<Enter>a
autocmd FileType tex nnoremap <F5> :!pdflatex<space><c-r>%<Enter>


" Shortcuts
autocmd FileType tex inoremap ,em \emph{}<Space><++><Esc>T{i
autocmd FileType tex inoremap ,bf \textbf{}<Space><++><Esc>T{i
autocmd FileType tex vnoremap , <ESC>`<i\{<ESC>`>2la}<ESC>?\\{<Enter>a
autocmd FileType tex inoremap ,it \textit{}<Space><++><Esc>T{i
autocmd FileType tex inoremap ,ol \begin{enumerate}<Enter><Enter>\end{enumerate}<Enter><Enter><++><Esc>3kA\item<Space>
autocmd FileType tex inoremap ,ul \begin{itemize}<Enter><Enter>\end{itemize}<Enter><Enter><++><Esc>3kA\item<Space>
autocmd FileType tex inoremap ,li <Enter>\item<Space>
autocmd FileType tex inoremap ,ref \ref{}<Space><++><Esc>T{i
autocmd FileType tex inoremap ,tab \begin{tabular}<Enter><++><Enter>\end{tabular}<Enter><Enter><++><Esc>4kA{}<Esc>i
autocmd FileType tex inoremap ,sc \textsc{}<Space><++><Esc>T{i
autocmd FileType tex inoremap ,chap \chapter{}<Enter><Enter><++><Esc>2kf}i
autocmd FileType tex inoremap ,sec \section{}<Enter><Enter><++><Esc>2kf}i
autocmd FileType tex inoremap ,ssec \subsection{}<Enter><Enter><++><Esc>2kf}i
autocmd FileType tex inoremap ,sssec \subsubsection{}<Enter><Enter><++><Esc>2kf}i
autocmd FileType tex inoremap ,col \begin{columns}[T]<Enter>\begin{column}{.5\textwidth}<Enter><Enter>\end{column}<Enter>\begin{column}{.5\textwidth}<Enter><++><Enter>\end{column}<Enter>\end{columns}<Esc>5kA



" -----[ GUI ]----- "

" This hides the Toolbar, Menubar and left/right scrollbar in gvim
if has("gui_running")
    set guioptions -=T
    set guioptions -=m
    set guioptions -=r
    set guioptions -=L
endif


" -----[ Fonts ]----- "
if has("gui_running")
    if has("gui_gtk2")
        set guifont=Hack\ 9 elseif has("gui_macvim")
        set guifont=Menlo\ Regular:h14
    elseif has("gui_win32")
        set guifont=Hack:h9:cANSI,Consolas:h11:cANSI
    endif
endif


" -----[ Panels ]----- "

" This remaps Ctrl+W +<direction> to Ctr+HJKL for changig the Panel in a
" splitted mode
map <C-h> <C-W>h
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-l> <C-W>l

" This is to get Tabs by using the <leader> Key (Leader Key: '\')
nmap <leader>1 1gt
nmap <leader>2 2gt
nmap <leader>3 3gt
nmap <leader>4 4gt
nmap <leader>5 5gt
nmap <leader>6 6gt


" -----[ MS Windows ]----- "

" Getting the Windows mswin behaviour
if has("win32")
    source $VIMRUNTIME/mswin.vim
    behave mswin
endif


if exists("b:current_syntax")
  finish
endif

" Conceal
hi Conceal guibg=NONE
setlocal cole=1
