syntax on
filetype plugin indent on
set ai
set number
set mouse=a
"set breakindent
set encoding=utf-8   "Added this for vim-hug
set nu rnu
set hidden
set tabstop=4
set shiftwidth=4
set keywordprg=:Man
let mapleader = "s"
set is
set tw=80
set so=10

"Colour settings
set t_Co=256 "Use 256 colours (Use this setting only if your terminal supports 256 colours)
set tgc "More terminal colours
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
let base16colorspace=256
colorscheme base16-nord

"Pymode stuff
let g:pymode_folding = 0

" turn hybrid line numbers off
":set nonumber norelativenumber
":set nonu nornu

" toggle hybrid line numbers
":set number! relativenumber!
":set nu! rnu!

"Triggers for number toggling
:augroup numbertoggle
:  autocmd!
:  autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
:  autocmd BufLeave,FocusLost,InsertEnter   * set norelativenumber
:augroup END

"CtrlP bindings
nmap <leader>d :CtrlPBuffer<cr>
nmap <leader>m :CtrlPMRU<cr>
nmap <leader>L :CtrlPLine<cr>

"NERDTree bingings
nnoremap <F1> :NERDTreeToggle<cr>
nnoremap <leader>t :NERDTreeFind<cr>
"autocmd vimenter * NERDTree


"Buffergator bindings
nmap gb :BuffergatorMruCyclePrev<cr>
nmap gn :BuffergatorMruCycleNext<cr>
nmap gto :BuffergatorTabsOpen<cr>
nmap gtc :BuffergatorTabsOpen<cr>
nmap gfo :BuffergatorOpen<cr>
nmap gfc :BuffergatorClose<cr>
let g:buffergator_autoexpand_on_split=0

"Stuff for faster movement and aesthetics
:set cursorline
nnoremap <leader>cd :cd %:p:h<cr>
nnoremap <F3> :tabprevious<cr>
nnoremap <F4> :tabnext<cr>
nnoremap <F5> :buffers<CR>:buffer<Space>
noremap <BS> <PageUp> 
noremap <Space> <PageDown> 
noremap <C-h> <C-W>h
noremap <C-l> <C-W>l
noremap <C-j> <C-W>j
noremap <C-k> <C-W>k
nnoremap <leader>z :w<cr>
nnoremap <leader>c :CtrlPChange<cr>
nnoremap <leader>C :CtrlPChangeAll<cr>
nnoremap <leader><cr> :center<cr>
inoremap jj <esc>

"Easymotion
map <Leader> <Plug>(easymotion-prefix)
map  / <Plug>(easymotion-sn)
omap / <Plug>(easymotion-tn)
map  n <Plug>(easymotion-next)
map  N <Plug>(easymotion-prev)
map <leader>ls <Plug>(easymotion-sl)
map <leader>lf <Plug>(easymotion-bd-fl)
map <leader>lw <Plug>(easymotion-bd-wl)
map <leader>ol <Plug>(easymotion-overwin-line)
map <leader>ow <Plug>(easymotion-overwin-w)
nmap <leader>of <Plug>(easymotion-overwin-f2)
nmap <leader>aw <Plug>(easymotion-bd-w)
nmap <leader>al <Plug>(easymotion-bd-jk)
let g:EasyMotion_smartcase = 1 " Infer search casing
let g:EasyMotion_startofline = 0 " keep cursor column when JK motion

"Copy and pasting
vmap <C-c> "+y
nmap <S-y> "+p

set guioptions-=m "menu bar 
set guioptions-=T "toolbar
set guicursor+=a:blinkon0 "Remove weird blinking cursor
"set guioptions-=r "scrollbar 
nmap <leader>T :vsplit <BAR> :wincmd l <BAR> :enew <cr>
"nmap <leader>bq :bp <BAR> bd #<cr>
nmap <leader>:ob :OpenBookmark<cr>
let g:deoplete#enable_at_startup = 1 "Enables deoplete
autocmd FileType python setlocal completeopt-=preview "Romoves docwindow for Jedi-vim

"Omnisharp taken from the ReadMe I think
let g:OmniSharp_timeout = 5
set completeopt=longest,menuone,preview
set previewheight=5
let g:ale_linters = { 'cs': ['OmniSharp'] }
let g:OmniSharp_highlight_types = 1
augroup omnisharp_commands autocmd!

" air-line
let g:airline_theme='tomorrow'
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#tab_nr_type = 1
let g:airline#extensions#tabline#show_tab_nr = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline#extensions#tabline#formatter = 'default'
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline#extensions#tabline#fnametruncate = 16
let g:airline#extensions#tabline#fnamecollapse = 2

"let mapleader=","

let g:airline#extensions#tabline#buffer_idx_mode = 1

nmap g1 <Plug>AirlineSelectTab1
nmap g2 <Plug>AirlineSelectTab2
nmap g3 <Plug>AirlineSelectTab3
nmap g4 <Plug>AirlineSelectTab4
nmap g5 <Plug>AirlineSelectTab5
nmap g6 <Plug>AirlineSelectTab6
nmap g7 <Plug>AirlineSelectTab7
nmap g8 <Plug>AirlineSelectTab8
nmap g9 <Plug>AirlineSelectTab9

let g:airline_powerline_fonts = 1

 if !exists('g:airline_symbols')
     let g:airline_symbols = {}
     endif

" unicode symbols
let g:airline_left_sep = '»'
let g:airline_left_sep = '▶'
let g:airline_right_sep = '«'
let g:airline_right_sep = '◀'
let g:airline_symbols.linenr = '␊'
let g:airline_symbols.linenr = '␤'
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.branch = '⎇'
let g:airline_symbols.paste = 'ρ'
let g:airline_symbols.paste = 'Þ'
let g:airline_symbols.paste = '∥'
let g:airline_symbols.whitespace = 'Ξ'

" airline symbols
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = ''

"Folding
nnoremap <leader>6 :setlocal fdm=indent<cr>
nnoremap <leader>7 :setlocal fdm=marker<cr>
nnoremap <leader>8 :setlocal fdm=expr<cr>:set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1<cr>
set foldmethod=indent
set foldlevelstart=1
autocmd FileType vim setlocal foldmethod=marker
autocmd FileType '' setlocal fdm=expr foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1

let javaScript_fold=1         " JavaScript
let perl_fold=1               " Perl
let php_folding=1             " PHP
let r_syntax_folding=1        " R
let ruby_fold=1               " Ruby
let sh_fold_enabled=1         " sh
let vimsyn_folding='af'       " Vim script
let xml_syntax_folding=1      " XML

"ctrlp and buffgator custom stuff 
let g:ctrlp_switch_buffer = 'E'
let g:ctrlp_custom_ignore = {
  \ 'dir':  '\v[\/](\.(git|hg|svn)|\_site|node_modules)$',
  \ 'file': '\v\.(exe|so|dll|class|png|jpg|jpeg)$',
\}
let g:ctrlp_working_path_mode = 'r' " Use the nearest .git directory as the cwd
let g:buffergator_viewport_split_policy = 'R' " Use the right side of the screen
let g:buffergator_suppress_keymaps = 1 " I want my own keymappings...

"Programming specific
"let g:auto_save_postsave_hook = 'silent !npx browser-sync reload &'
" let g:go_def_mode='gopls'
" let g:go_info_mode='gopls'

"NNN
"let g:nnn#layout = { 'left': '~20%'  } " or right, up, down
let g:nnn#layout = { 'window': { 'width': 0.9, 'height': 0.6, 'highlight': 'Debug'  }  }
let g:nnn#action = {
      \ '<c-t>': 'tab split',
      \ '<c-x>': 'split',
      \ '<c-v>': 'vsplit' }
let $NNN_BMS='h:~/;c:~/.config;n:~/Notes;'
let $NNN_PLUG='p:preview-tui;c:x2sel;i:imgview;s:tmspawn'
"let $NNN_FIFO=/tmp/nnn.fifo


" Prettier settings
" let g:prettier#config#config_precedence = 'file-override'
let g:prettier#autoformat = 1
let g:prettier#autoformat_require_pragma = 0
let g:prettier#config#tab_width = 4
" let g:prettier#config#use_tabs = 'false'
