vim.o.updatetime     = 100
vim.o.scrolloff      = 3
vim.o.sidescrolloff  = 5
vim.o.textwidth      = 78
vim.o.linespace      = 0
vim.o.showmatch      = true
vim.o.modeline       = true
vim.o.showmode       = false
vim.o.splitbelow     = true
vim.o.splitright     = true
vim.o.foldenable     = false
vim.o.undofile       = true
vim.o.autochdir      = false
vim.o.startofline    = false
vim.o.ignorecase     = true
vim.o.smartcase      = true
vim.o.magic          = true
vim.o.termguicolors  = true
vim.o.fileformat     = 'unix'
vim.o.inccommand     = 'split'
vim.o.mouse          = ''
vim.o.completeopt    = 'menuone,noselect'
vim.o.wildmode       = 'longest:full,full'
vim.o.wildoptions    = 'pum'
vim.o.pumblend       = 30
vim.o.backup         = false
vim.o.writebackup    = false
vim.o.swapfile       = false
vim.o.sessionoptions = 'buffers,curdir,tabpages,winsize'
vim.o.shada          = ''
vim.o.diffopt        = 'filler,internal,algorithm:histogram,indent-heuristic,closeoff,linematch:60'
vim.o.scrolloff      = 999
vim.o.formatoptions  = "crqn1j"
vim.o.signcolumn     = "auto:1-2"
vim.o.spelllang      = "en_gb"
vim.o.spelloptions   = "camel,noplainbuffer"
vim.o.spell          = true

-- Disable providers we do not give a shit about
vim.g.loaded_python3_provider = 0
vim.g.loaded_python_provider  = 0
vim.g.loaded_ruby_provider    = 0
vim.g.loaded_perl_provider    = 0
vim.g.loaded_node_provider    = 0

-- Disable some in built plugins completely
vim.g.loaded_netrw            = 1
vim.g.loaded_netrwPlugin      = 1
vim.g.loaded_matchparen       = 1
vim.g.loaded_matchit          = 1
vim.g.loaded_2html_plugin     = 1
vim.g.loaded_getscriptPlugin  = 1
vim.g.loaded_gzip             = 1
vim.g.loaded_logipat          = 1
vim.g.loaded_rrhelper         = 1
vim.g.loaded_spellfile_plugin = 1
vim.g.loaded_tarPlugin        = 1
vim.g.loaded_vimballPlugin    = 1
vim.g.loaded_zipPlugin        = 1

-- Map leader
vim.g.mapleader                     = " "
vim.g.maplocalleader                = ","
-- vim-dispatch
vim.g.dispatch_no_maps              = 1
-- vim-matchup
vim.g.matchup_matchparen_offscreen  = { method = 'popup', fullwidth = true }
vim.g.matchup_surround_enabled      = 1
-- No default mappings for tmux navigator
vim.g.tmux_navigator_no_mappings    = 1
-- Write the current buffer, but only if changed before navigating from Vim to tmux pane
vim.g.tmux_navigator_save_on_switch = 1
-- Disable ]]/[[ style bindings
vim.g.no_rust_maps                  = 1

if os.getenv("SSH_CONNECTION") then
  local osc52 = require('vim.ui.clipboard.osc52')
  vim.g.clipboard = {
    name = 'OSC 52',
    copy = {
      ['+'] = osc52.copy,
      ['*'] = osc52.copy,
    },
    paste = {
      ['+'] = osc52.paste,
      ['*'] = osc52.paste,
    },
  }
else
  -- See :help clipboard and https://github.com/neovim/neovim/issues/14545
  vim.g.clipboard = {
    name = "clipboard",
    copy = {
      ["+"] = "wl-copy",
      ["*"] = "wl-copy"
    },
    paste = {
      ["+"] = "wl-paste",
      ["*"] = "wl-paste"
    },
    cache_enabled = true
  }
end

-- We do this to prevent the loading of the system fzf.vim plugin. This is
-- present at least on Arch/Manjaro
vim.cmd.set{ args = { 'rtp-=/usr/share/vim/vimfiles' } }
-- Disable virtual text for all diagnostics
vim.diagnostic.config({
  underline        = true,
  signs            = true,
  virtual_text     = false,
  update_in_insert = false,
  severity_sort    = true,
  float = {
    header      = false,
    source      = 'always',
    border      = 'rounded',
    focusable   = false,
  },
})

require 'plugins'
require 'autocmd'
require 'keymappings'
require 'lsp'
require 'treesitter'

-- Setup and load colour scheme
require("monokai-nightasty").setup({
  dark_style_background = "transparent",
  on_highlights = function(highlights, colors)
    highlights.StatusLine   = { bg = "#000000" }
    highlights.StatusLineNC = { bg = "#000000" }
  end,
})
vim.cmd.colorscheme('monokai-nightasty')
