local global_vars = {
    -- Disable default vim plugins
    loaded_gzip = 1,
    loaded_tar = 1,
    loaded_tarPlugin = 1,
    loaded_zip = 1,
    loaded_zipPlugin = 1,
    loaded_getscript = 1,
    loaded_getscriptPlugin = 1,
    loaded_vimball = 1,
    loaded_vimballPlugin = 1,
    loaded_matchit = 1,
    loaded_matchparen = 1,
    loaded_2html_plugin = 1,
    loaded_logiPat = 1,
    loaded_rrhelper = 1,
    loaded_netrw = 1,
    loaded_netrwPlugin = 1,
    loaded_netrwSettings = 1,
    loaded_netrwFileHandlers = 1,

    -- Leader keys
    mapleader = ' ',
    maplocalleader = ',',
    -- TeX flavor
    tex_flavor = 'latex',

    -- Custom variables
    border_style = 'rounded',
}

local vim_options = {
    -- General settings
    termguicolors = true,
    mouse = 'nv',
    errorbells = false,
    visualbell = false,
    -- hidden = true,
    fileformats = 'unix',
    magic = true,
    virtualedit = 'block',
    encoding = 'utf-8',
    fileencoding = 'utf-8',
    clipboard = 'unnamedplus',
    wildignorecase = true,
    wildignore =
        '.git,.hg,.svn,*.pyc,*.o,*.out,*.jpg,*.jpeg,*.png,*.gif,*.zip,**/tmp/**,*.DS_Store,**/node_modules/**',
    -- history = 10000,
    -- showmode = false,
    jumpoptions = 'stack',
    formatoptions = '1jcroql',
    shortmess = 'aoOTIcF',
    -- startofline = false,
    wrap = false,
    sidescrolloff = 4,
    scrolloff = 4,
    whichwrap = '<,>,[,],~',
    -- ruler = true,
    -- display = 'lastline',
    -- colorcolumn = '80',
    -- cursorcolumn = true,
    cursorline = true,
    cursorlineopt = 'number',
    -- backspace = 'indent,eol,start',
    showcmd = false,
    -- inccommand = 'nosplit',
    -- cmdheight = 2,
    -- cmdwinheight = 6,
    showtabline = 2,
    -- laststatus = 2,
    -- textwidth = 80,
    synmaxcol = 2500,
    shell = 'sh',
    grepformat = '%f:%l:%c:%m',
    grepprg = 'rg --hidden --vimgrep --smart-case --',
    diffopt = 'filler,iwhite,internal,algorithm:patience',

    -- CVE-2019-12735 (it is patched, but just to be cautious)
    -- I don't use modeline personally anyway
    modeline = false,
    modelines = 0,

    -- Spell checking, dictionary
    -- spell = true,
    -- spellfile = vim.fn.stdpath('config') .. '/spell/en.utf-8.add',
    -- dictionary = { '/usr/share/dict/american-english' },

    -- Transparency
    pumblend = 0,
    winblend = 0,

    -- Conceal
    conceallevel = 2,
    concealcursor = 'niv',
    foldenable = false,
    foldlevelstart = 99,

    -- Case insensitive
    ignorecase = true,
    smartcase = true,
    infercase = true,

    -- Searching
    -- incsearch = true,
    hlsearch = true,
    -- wrapscan = true,

    -- Update time
    -- timeout = true,
    -- ttimeout = true,
    timeoutlen = 500,
    ttimeoutlen = 25,
    updatetime = 150,
    redrawtime = 1500,
    lazyredraw = true,

    -- No swapfile
    backup = false,
    writebackup = false,
    swapfile = false,

    -- Completion menu
    -- wildmenu = true,
    wildmode = 'full',
    complete = '.,w,b,k',
    completeopt = 'menu,menuone,noselect',
    pumheight = 16,
    helpheight = 12,
    previewheight = 12,

    -- Window rules
    splitbelow = true,
    splitright = true,
    switchbuf = 'useopen',
    winwidth = 30,
    winminwidth = 10,
    equalalways = false,

    -- Left column
    signcolumn = 'auto:4',
    number = true,
    relativenumber = true,
    -- numberwidth = 6,

    -- 4 spaces = 1 tab
    shiftwidth = 4,
    tabstop = 4,
    softtabstop = -1, -- fallback to 'shiftwidth'
    smarttab = true,
    expandtab = true,
    smartindent = true,
    -- autoindent = true,
    shiftround = true,

    -- Trailings, line break
    list = true,
    listchars = 'tab:»·,nbsp:+,trail:·,extends:→,precedes:←',
    showbreak = '↳  ',
    -- linebreak = true,
    -- breakat = [[\ \	;:,!?]],
    breakindent = true,
    -- breakindentopt = 'shift:4,min:20',

    -- Undo file path
    undofile = true,
    -- undodir = vim.fn.stdpath('data') .. '/undo',
}

local function load_options(vars, opts)
    -- Set colorscheme
    vim.api.nvim_command('colorscheme {{ theme }}')

    -- Only use python3
    vim.opt.pyxversion = 3
    vim.g.python3_host_prog = '/usr/bin/python3'
    vim.g.loaded_python_provider = 0 -- disable python2 support

    -- Load global variables
    for k, v in pairs(vars) do
        vim.g[k] = v
    end

    -- Load editor options
    for k, v in pairs(opts) do
        vim.opt[k] = v
    end
end

load_options(global_vars, vim_options)
