"pathogen stuff {{{ "clone plugins to .vim/bundle
    "filetype off "temporarily turn off filetype options
    "call pathogen#infect() "load pathogen
    "filetype plugin indent on "load filetype-specific indent / plugin files
    "TODO: remove this
"}}}

"vim-plug {{{
    "automatic installation
    if empty(glob('~/.vim/autoload/plug.vim'))
        silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
        \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
        autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
    endif

    call plug#begin('~/.vim/plugins')

    Plug 'junegunn/vim-easy-align'
    Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin --all' }
    Plug 'tpope/vim-surround'
    Plug 'tpope/vim-commentary'
    Plug 'w0rp/ale'
    Plug 'airblade/vim-gitgutter'
    Plug 'itchyny/lightline.vim'
    Plug 'tpope/vim-repeat'
    Plug 'haya14busa/incsearch.vim'
    Plug 'gorodinskiy/vim-coloresque'
    Plug 'sheerun/vim-polyglot'
    Plug 'nvie/vim-flake8'
    Plug 'KKPMW/sacredforest-vim'
    Plug 'wolf-dog/lightline-sceaduhelm.vim'
    Plug 'unblevable/quick-scope'
    Plug 'tpope/vim-fugitive'
    " Plug 'metakirby5/codi.vim'

    call plug#end()

"}}}

"appearance {{{
    colorscheme zenburn
    syntax on "enable syntax
    set encoding=utf-8 "keep utf-8 encoding
    set scrolloff=3 "keep at least 3 lines above and below cursor
    set showmode "something something buffers
    set showcmd "show command in bottom bar
    set wildmenu "visual autocomplete for command menu
    set wildmode=list:longest "show all completions on tab
    set laststatus=2 "last window will always have statusline
    set showmatch "highlight matching [{()}]
    set cursorline "highlight current line

    "remove underline on current line number
    hi CursorLineNr    cterm=bold 

    "lightline
    let g:lightline = { 'colorscheme': 'sceaduhelm', }
    set fillchars+=vert:│
"    }}}

"movement {{{
    " TODO: map alt-j and k to move text lines vertically, maintaining indent
" }}}

"folding {{{
    set foldenable "enable folding
    set foldmethod=marker "fold sections by marker
    set foldlevel=0 "fold by default
    set modelines=1 "check final line of file for modeline
"}}}

"behavior {{{
    set nocompatible "turn off vi compatability nonsense
    set hidden "hide buffer when opening new file
    set visualbell "use visual bell instead of beeping
    set ttyfast "improves smoothness and drawing
    set backspace=indent,eol,start "always allow backspacing
    set undofile "make .un file for persistent undo
    set relativenumber "make numbers relative to current line
    set lazyredraw "redraw only when necessary
"}}} 

"searching {{{
    set gdefault "remove default g flag on search
    set ignorecase "ignore case for searches
    set smartcase "case-specific only when uppercase
    set hlsearch "don't continue to highlight searched phrases.
    set incsearch "but do search as characters are entered
    "remap tab to jump by brackets
    nnoremap <tab> %
    vnoremap <tab> %
"}}}

"tab settings {{{
    set tabstop=4 " number of visual spaces per tab
    set softtabstop=4 "should always = tabstop
    set shiftwidth=4 "indent/outdent by 4 columns
    set expandtab "tabs are spaces
    set shiftround "always indent/outdent to the nearest tabstop
    "make search terms more visible
    highlight Visual ctermbg=DarkGreen ctermfg=Black
    set autoindent "auto indentation
"}}}

"ruler settings {{{
    set rulerformat=%l,%-2v\|%4L\ Lines "display line, column, and total lines
    set ruler "turn on ruler
"}}}

"long line handling {{{
    set textwidth=79
    set fo=
    set fo=t
"   set colorcolumn=85
"}}}

"leaders {{{
    :let mapleader = ","

    "clear search highlighting with leader-space
    nnoremap <leader><space> :noh<cr>
    
    "underline with line of the same length
    nnoremap <leader>- yypv$r-

    "insert date on current line
    nnoremap <leader>d k :r !date <cr>
"}}}

"invisible characters {{{
    set list
    set listchars=tab:▸\ ,eol:¬
"}}}

"hjkl {{{
    "disable arrow keys in normal and visual mode
    nnoremap <up> <nop>
    nnoremap <down> <nop>
    nnoremap <left> <nop>
    nnoremap <right> <nop>
    inoremap <up> <nop>
    inoremap <down> <nop>
    inoremap <left> <nop>
    inoremap <right> <nop>
    "disable h and l
    " nnoremap h <nop>
    " nnoremap l <nop>
    "make j and k move by screen line, not file line
    nnoremap j gj
    nnoremap k gk
"}}}

"split pane navigation {{{
    "map vertical split to \ w, switch to it, open explorer, prompt for filename
    "TODO: make new window prompt use fzf
    nnoremap <leader>w <C-w>v<C-w>l:e <C-S-d><BS><BS>open 
    "switch panes wit ctrl + h/j/k/l
    nnoremap <C-h> <C-w>h
    nnoremap <C-j> <C-w>j
    nnoremap <C-k> <C-w>k
    nnoremap <C-l> <C-w>l
    "map resize pane
    "TODO: remap pane resize to something else (leader?)
    map + :vertical resize +5<CR>
    map - :vertical resize -5<CR>
    "quick-scope
    " Trigger a highlight in the appropriate direction when pressing these keys:
    let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']

    augroup qs_colors
        autocmd!
        autocmd ColorScheme * highlight QuickScopePrimary guifg='#afff5f' gui=underline ctermfg=155 cterm=underline
        autocmd ColorScheme * highlight QuickScopeSecondary guifg='#5fffff' gui=underline ctermfg=81 cterm=underline
    augroup END

"}}}

"launch love game, check youtube love2d roguelike+rpg day 1 if broken {{{
    map ,t :! /Applications/love.app/Contents/MacOS/love . <CR>
"}}}

"file specific {{{
    "in markdown files, when writing add two spaces to each line to fix spacing 
    "in compiled version
    au BufWritePost *.md silent! %s/[^ ]\zs$/\1  /
    "bold something in a markdown file
    :au FileType markdown nmap <leader>b i**<esc>ea**<esc>b
    "python
    "au BufNewFile,BufRead *.py
    "\ set tabstop=4
    "\ set softtabstop=4
    "\ set shiftwidth=4
    "\ set textwidth=79
    "\ set expandtab
    "\ set autoindent
    "\ set fileformat=unix
    ""webdev
    "au BufNewFile,BufRead *.js, *.html, *.css
    "\ set tabstop=2
    "\ set softtabstop=2
    "\ set shiftwidth=2
"}}}

"plugin modification {{{
    "FZF
       map <C-p> :FZF<cr>
     " This is the default extra key bindings
        let g:fzf_action = {
        \ 'ctrl-t': 'tab split',
        \ 'ctrl-x': 'split',
        \ 'ctrl-v': 'vsplit' }

        " Default fzf layout
        " - down / up / left / right
        let g:fzf_layout = { 'down': '~30%' }

        " Customize fzf colors to match your color scheme
        let g:fzf_colors =
        \ { 'fg':      ['fg', 'Normal'],
        \ 'bg':      ['bg', 'Normal'],
        \ 'hl':      ['fg', 'Comment'],
        \ 'fg+':     ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
        \ 'bg+':     ['bg', 'CursorLine', 'CursorColumn'],
        \ 'hl+':     ['fg', 'Statement'],
        \ 'info':    ['fg', 'PreProc'],
        \ 'border':  ['fg', 'Ignore'],
        \ 'prompt':  ['fg', 'Conditional'],
        \ 'pointer': ['fg', 'Exception'],
        \ 'marker':  ['fg', 'Keyword'],
        \ 'spinner': ['fg', 'Label'],
        \ 'header':  ['fg', 'Comment'] }
     " EasyAlign
     "" Start interactive EasyAlign in visual mode (e.g. vipga)
     xmap ga <Plug>(EasyAlign)
     " Start interactive EasyAlign for a motion/text object (e.g. gaip)
     nmap ga <Plug>(EasyAlign)

"}}}

"folding options, this must be last in file
" vim:foldmethod=marker:foldlevel=0

"todo:
    "clean up folding
    "make windows-specific plugin install using conditional activation setting here:
        "https://github.com/junegunn/vim-plug/wiki/tips#automatic-installation
    "to install:
        "emmett
        "codi
        "fugitive
        "vimwiki
        " Plug 'terryma/vim-multiple-cursors'
        " Plug 'ryanss/vim-hackernews'
        " Plug 'mbbill/undotree' or Plug 'sjl/gundo.vim'
        " Plugin 'tpope/vim-projectionist'
        " Plug 'mileszs/ack.vim'
        " Plug 'vim-scripts/grep.vim'
        " Plug 'jpalardy/vim-slime' (maybe not with codi?)
        " Plug 'vim-pandoc/vim-pandoc'
        " Plugin 'alfredodeza/pytest.vim'
        " Plug 'docker/docker'
        " Plug 'tyrannicaltoucan/vim-quantum'
        " Plug vim-scripts/indentpython.vim
        " bind :bnext :blast (leader n, leader p?) map gn :bn<cr>  (:bd for
        " delete and unload) (unimpaired?) (buffer fzf?)
        " csv.vim
        "
