" Install vim-plug if missing
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
  augroup VimPlugAutoInstall
    autocmd!
    autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
  augroup END
endif

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

" List Plugins =====================================

" delete unused buffers
Plug 'schickling/vim-bufonly'

" Legacy Vim {{{

" Compatibility for legacy vim with neovim's async api
if !has('nvim')
  Plug 'roxma/vim-hug-neovim-rpc'
  Plug 'roxma/nvim-yarp'
endif

" }}}

" Dependencies: {{{
  " Create custom text objects (required by rubyblock,xmlattr, vim-textobj-elixir)
  Plug 'kana/vim-textobj-user'

  " Vim Web API (required by gist-vim)
  Plug 'mattn/webapi-vim'

  " fzf greatness (fuzzy finding)
  Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }
  Plug 'junegunn/fzf.vim'
" }}}

" COC {{{
  if executable('yarn') && executable('node') " && has('nvim')
    let g:coc_global_extensions = [
          \ 'coc-css',
          \ 'coc-dictionary',
          \ 'coc-eslint',
          \ 'coc-git',
          \ 'coc-github',
          \ 'coc-gitignore',
          \ 'coc-gocode',
          \ 'coc-highlight',
          \ 'coc-html',
          \ 'coc-json',
          \ 'coc-neosnippet',
          \ 'coc-omni',
          \ 'coc-prettier',
          \ 'coc-rls',
          \ 'coc-snippets',
          \ 'coc-solargraph',
          \ 'coc-svg',
          \ 'coc-syntax',
          \ 'coc-tslint-plugin',
          \ 'coc-tsserver',
          \ 'coc-ultisnips',
          \ 'coc-vimlsp',
          \ 'coc-yaml',
          \ 'coc-yank',
          \ ]
    Plug 'neoclide/coc.nvim', {'branch': 'release'}
  endif
" }}}

" Testing {{{
    " run tests at the speed of thought
    Plug 'janko-m/vim-test'
" }}}

" Terminal {{{
    " abstraction on top of neovim terminal
    Plug 'kassio/neoterm'

    " floating terminal
    Plug 'voldikss/vim-floaterm'
" }}}

" Neovim: {{{
  if has('nvim')

    " Highlight Yanked String
    Plug 'machakann/vim-highlightedyank'

    if !exists('$TMUX')
      " simulate tmux shortcuts in neovim
      Plug 'hkupty/nvimux'
    endif
  endif
" }}}

" Git: {{{
  " Asynchronously control git repositories in Neovim/Vim 8
  Plug 'lambdalisue/gina.vim'

  " Visual git gutter
  " Plug 'airblade/vim-gitgutter'

  Plug 'mhinz/vim-signify'

  " Gitv - for browsing a file's history in git
  Plug 'gregsexton/gitv'

  " A better Gitv?
  Plug 'junegunn/gv.vim'

  " git awesomeness
  Plug 'tpope/vim-fugitive'

    " github support for fugitive
    Plug 'tpope/vim-rhubarb'

" }}}

" Gleam: {{{
  " Gleam language support
  Plug 'gleam-lang/gleam.vim'
" }}}

" Erlang: {{{
  " syntax
  Plug 'vim-erlang/vim-erlang-runtime'
" }}}

" Elixir: {{{
  " Elixir support
  Plug 'elixir-lang/vim-elixir'

  " elixir text objects
  Plug 'duff/vim-textobj-elixir'

  " pulls info on hex packages (requires mattn/webapi-vim)
  Plug 'lucidstack/hex.vim', { 'for': 'elixir'}
" }}}

" Ruby: {{{
  " do rspec things and highlight syntax
  Plug 'thoughtbot/vim-rspec', { 'for': ['ruby', 'rspec'] }

  " get gem info and insert latest gem version into Gemfile
  Plug 'alexbel/vim-rubygems', { 'for': 'ruby' }

  " interact with ruby bundler gem
  Plug 'tpope/vim-bundler', { 'for': ['ruby', 'rspec'] }

  " vim rake by Tim Pope - like rails.vim but for plain ruby
  Plug 'tpope/vim-rake', { 'for': ['ruby', 'rspec'] }

  " support for ruby
  Plug 'vim-ruby/vim-ruby', { 'for': ['ruby', 'rspec']}

  " vim cucumber for easy cuke navigation
  Plug 'tpope/vim-cucumber', { 'for': ['gherkin', 'ruby'] }

  " syntax highlighting for rspec
  Plug 'keith/rspec.vim', { 'for': ['ruby', 'rspec'] }

  " show code coverage in vim
  Plug 'killphi/vim-legend', { 'for': 'ruby' }

  " Rails and ruby support (loaded automatically for rails apps)
  Plug 'tpope/vim-rails'

  " Text object for ruby blocks
  Plug 'nelstrom/vim-textobj-rubyblock'

  " refactoring tools for ruby/rspec
  Plug 'pablobfonseca/vim-ruby-refactoring', { 'for': 'ruby' }
" }}}

" GraphQL {{{
  Plug 'jparise/vim-graphql'
" }}}

" TimPope: {{{
  " Vim sugar for the UNIX shell commands that need it the most.
  Plug 'tpope/vim-eunuch'

  " allow (non-native) plugins to use the . command
  Plug 'tpope/vim-repeat'

  " Surround text with closures
  Plug 'tpope/vim-surround'

  " vim projectionist allows creating :Esomething custom shortcuts (required by vim rake)
  Plug 'tpope/vim-projectionist'

  " vim unimpaired fixes daily annoyences
  Plug 'tpope/vim-unimpaired'

  " abolish.vim: easily search for, substitute, and abbreviate multiple variants
  " of a word
  Plug 'tpope/vim-abolish'

  " Support emacs keybindings in insert mode
  Plug 'tpope/vim-rsi'

  " Clojure REPL in Vim
  Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

  " save vim sessions
  Plug 'tpope/vim-obsession'

  " " Comment out code easily
  Plug 'tpope/vim-commentary'
" }}}

" Navigation: {{{
  " navigate to directory of current file using `-`
  Plug 'tpope/vim-vinegar'

  " Navigate symbols and tags using LSPs/ctags
  Plug 'liuchengxu/vista.vim'
" }}}

" NERDTree: {{{
  " NERDTree... tree explorer for vim
  Plug 'scrooloose/nerdtree'

  " Nerdtree show git status
  Plug 'Xuyuanp/nerdtree-git-plugin'

  " highlight file icons with different colors
  Plug 'tiagofumo/vim-nerdtree-syntax-highlight'

  Plug 'justinmk/vim-dirvish'
" }}}

" HTML: {{{
  " Emmet: generates html tags, autocomplete css
  Plug 'mattn/emmet-vim'

  " RagTag: Auto-close html tags + mappings for template scripting languages
  Plug 'tpope/vim-ragtag'

  " add text object for HTML attributes - allows dax cix etc
  Plug 'whatyouhide/vim-textobj-xmlattr'
" }}}

" WebAssembly: {{{
  " Syntax Highlighting:
  Plug 'rhysd/vim-wasm', { 'for': 'wasm' }
" }}}

" Searching: {{{
  " highlights all search results and allows tabbing between them
  Plug 'haya14busa/incsearch.vim'

  " Sublime text like search results
  Plug 'dyng/ctrlsf.vim', { 'on': 'CtrlSF' }

  " RipGrep - grep is dead. All hail the new king RipGrep.
  Plug 'jremmen/vim-ripgrep'
" }}}

" Align Code: {{{
  " same as tabular but by Junegunn and way easier
  Plug 'junegunn/vim-easy-align'

  " move function arguments
  Plug 'AndrewRadev/sideways.vim'
" }}}

" TMUX: {{{
  " .tmux.conf syntax highlighting
  Plug 'keith/tmux.vim', { 'for': 'tmux' }

  " tmux config file stuff
  Plug 'tmux-plugins/vim-tmux', { 'on': 'Mux' }

  " vim slime for tmux integration (C-c, C-c to send selction to tmux)
  Plug 'jpalardy/vim-slime', { 'on': 'Mux' }

  " seamless tmux/vim pane navigation
  Plug 'christoomey/vim-tmux-navigator', { 'on': 'Mux' }

  " yet another tmux plugin
  Plug 'benmills/vimux', { 'on': 'Mux' }
    " Run Golang tests in vimux
    Plug 'benmills/vimux-golang', { 'on': 'Mux' }

    " Run elixir mix tests in vimux
    Plug 'spiegela/vimix', { 'on': 'Mux' }

    " Run ruby and elixir tests
    Plug 'jgdavey/vim-turbux', { 'on': 'Mux' }

  " autocomplete using text from tmux
  Plug 'wellle/tmux-complete.vim', { 'on': 'Mux' }
" }}}

" Snippets: {{{
  " ES2015 code snippets (Optional)
  Plug 'epilande/vim-es2015-snippets', { 'for': ['javascript', 'javascript.jsx'] }

  " React code snippets
  Plug 'epilande/vim-react-snippets', { 'for': ['javascript', 'javascript.jsx'] }

  " vim snippets for UltiSnips ...
  if has('nvim')
    Plug 'honza/vim-snippets'
  endif

  " modern snippets for vim
  Plug 'SirVer/ultisnips'

  " neosnippet snippets
  Plug 'Shougo/neosnippet'
  Plug 'Shougo/neosnippet-snippets'
" }}}

" JavaScript: {{{
  " JavaScript support (required by vim-jsx)
  Plug 'pangloss/vim-javascript'

  " React:
    " JSX support for react components
    Plug 'mxw/vim-jsx'

    " A Vim plugin that provides functions that modify React source files 
    Plug 'mvolkmann/vim-react', { 'for': 'javascript.jsx' }

    " extract partial render, rename tag, select self close tags
    Plug 'samuelsimoes/vim-jsx-utils', { 'for': 'javascript.jsx' }

  " JSON manipulation
  Plug 'tpope/vim-jdaddy', { 'for': 'json' }

  " syntax highlighting for styled components
  Plug 'styled-components/vim-styled-components', { 'branch': 'main', 'for': 'javascript.jsx' }
" }}}

" MDX (Gatsby Markdown with React) {{{
  Plug 'jxnblk/vim-mdx-js'
" }}}

" TypeScript: {{{
Plug 'leafgarland/typescript-vim'
Plug 'ianks/vim-tsx'
"}}}

" Elm: {{{
  " elm editing and compilation in vim
  Plug 'ElmCast/elm-vim'
" }}}

" ColorSchemes: {{{
  " One Dark
  Plug 'joshdick/onedark.vim'

  " vim one
  Plug 'rakr/vim-one'
" }}}

" Postgres: {{{
  " postgres sql highlighting
  Plug 'exu/pgsql.vim'

  " show table description in vim
  Plug 'hashrocket/vim-hr-psql', { 'on': 'Pgtable' }
" }}}

" Writing: {{{
  " distraction free writing (like iA Writer)
  Plug 'laktek/distraction-free-writing-vim', { 'on': 'ToggleDistractionFreeWriting' }

  " Distraction free writing in vim
  Plug 'junegunn/goyo.vim', { 'on': 'Goyo' }

  " Highlight current paragraph (works well with goyo)
  Plug 'junegunn/limelight.vim', { 'on': 'Limelight' }

  " integration with Deckset macOS app
  Plug 'bwmcadams/vim-deckset', { 'for': 'markdown' }
" }}}

" Terraform: {{{
  " terraform syntax
  Plug 'hashivim/vim-terraform' 
" }}}

" Docker {{{
Plug 'ekalinin/Dockerfile.vim', {'for' : 'Dockerfile'}
" }}}

" Ansible: {{{
  " ansible vim plugin
  Plug 'pearofducks/ansible-vim'
" }}}

" Caddy: {{{
  " syntax highlighting for caddyfile
  Plug 'isobit/vim-caddyfile', { 'for': 'Caddyfile' }
" }}}

" GITHUB: {{{
  " Browse github
  Plug 'junegunn/vim-github-dashboard', { 'on': ['GHDashboard', 'GHActivity'] }

  " Vim GitHub gist integration
  Plug 'mattn/gist-vim', { 'on': 'Gist' }
" }}}

" PIVOTAL "{{{
  " Complete pivotal tracker stories
  Plug 'hauleth/pivotaltracker.vim'
" }}}"

" Airline {{{
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'enricobacis/vim-airline-clock'
" }}}

" Crystal: {{{
  Plug 'rhysd/vim-crystal'
" }}}

" Haskell: {{{
  Plug 'neovimhaskell/haskell-vim', { 'for': 'haskell' }
" }}}

" Swift: {{{
  Plug 'keith/swift.vim', { 'for': 'swift' }
" }}}

" Golang: {{{
  Plug 'fatih/vim-go', { 'for': 'go' }
" }}}

" CSS/SCSS {{{
  " up to date CSS3 syntax highlighting
  Plug 'hail2u/vim-css3-syntax'

  " css language server
  Plug 'vscode-langservers/vscode-css-languageserver-bin'
" }}}

" VimScript: {{{
  " vim plugin for writing vim plugins
  Plug 'tpope/vim-scriptease'
"}}}

" Format+Lint: {{{
  " staticly check code and highlight errors (async syntastic replacement)
  Plug 'w0rp/ale'
" }}}

" Quickfix List: {{{
  Plug 'romainl/vim-qf'
" }}}

" Other: {{{
  " window animations
  Plug 'camspiers/animate.vim'

  " resize windows automatically if too small
  Plug 'camspiers/lens.vim'

  " open Finder / Terminal for file under the cursor
  Plug 'justinmk/vim-gtfo'

  " share code screenshots with Carbon Now
  Plug 'kristijanhusak/vim-carbon-now-sh'

  " replacement for matchit
  Plug 'andymass/vim-matchup'

  " profiling vim startup
  Plug 'tweekmonster/startuptime.vim'

  " add `end` automatically when creating a closure in many languages
  Plug 'tpope/vim-endwise'

  " auto-generate ctags on save
  Plug 'jsfaint/gen_tags.vim'

  " Multiple cursor emulation (a la Sublime Text) using ctrl-n
  Plug 'terryma/vim-multiple-cursors'

  " get docs for command under cursor (with Dash or web) (mapped to gK)
  Plug 'keith/investigate.vim'

  " show trailing white spaces and allow deleting them
  Plug 'ntpeters/vim-better-whitespace'

  " Indent lines (visual indication)
  Plug 'Yggdroot/indentLine'

  " syntax for apple scripts
  Plug 'vim-scripts/applescript.vim', { 'for': ['scpt', 'applescript', 'scptd'] }

  " Jekyll blog commands
  Plug 'parkr/vim-jekyll'

  " Integration testing for vim plugins
  Plug 'junegunn/vader.vim'

  " The ultimate undo history visualizer for VIM
  Plug 'mbbill/undotree'

  " Convert code to multiline
  Plug 'AndrewRadev/splitjoin.vim'

  " Toggle between different language verbs or syntax styles
  Plug 'AndrewRadev/switch.vim'
  " fancy vim start page
  Plug 'mhinz/vim-startify'

  " copy code as rtf
  Plug 'zerowidth/vim-copy-as-rtf', { 'on': 'CopyRTF' }

  " Rust support
  Plug 'rust-lang/rust.vim', { 'for': 'rust' }

  " Scratch buffers
  Plug 'mtth/scratch.vim'

  " interactive scratchpad
  Plug 'metakirby5/codi.vim'

  " resize windows in vim naturally
  Plug 'simeji/winresizer', { 'on': 'WinResizerStartResize' }

  "' File icons in vim --- keep at the bottom, below airline, nerdtree and startify
  Plug 'ryanoasis/vim-devicons'
"}}}

" OWN PLUGINS: {{{
  " automatic bulleted lists
  Plug 'dkarter/bullets.vim'

  " snip helpers - assorted functions for snippets
  Plug 'dkarter/sniphelpers.vim'

  " routes for rails, phoenix etc
  " Plug 'dkarter/routes.nvim', { 'dir': '~/dev/vim-plugins/routes.nvim' }
" }}}

" ==================================================

if filereadable(expand('~/.vimrc.bundles.local'))
  source ~/.vimrc.bundles.local
endif

call plug#end()