-- HELPERS ----------------------------------------------------
local cmd = vim.cmd  -- to execute Vim commands e.g. cmd('pwd')
local fn = vim.fn    -- to call Vim functions e.g. fn.bufnr()
local g = vim.g      -- a table to access global variables
local scopes = {o = vim.o, b = vim.bo, w = vim.wo}


cmd "syntax on"
-- 相對行號顯示
-- cmd "set relativenumber"
-- 絕對行號顯示
-- cmd "set number"
-- 混合模式，同時顯示相對行號和絕對行號
cmd "set number relativenumber"
cmd "set tabstop=2"
cmd "set shiftwidth=2"
cmd "set expandtab"
cmd "set nofoldenable"

-- always show status
cmd "set laststatus=2"

-- show cursor position
cmd "set ruler"
cmd "set cursorline"
cmd "set cursorcolumn"
cmd "set hlsearch"

-- no wrap line
cmd "set nowrap"

-- enable backspace
cmd "set backspace=indent,eol,start"
cmd "set encoding=utf-8"
cmd "set completeopt=menu,menuone,noselect"
cmd "set noswapfile"
cmd "set mouse="

cmd "set background=dark"

cmd "filetype indent on"
cmd "filetype on"
cmd "filetype plugin on"

vim.api.nvim_create_autocmd("ColorScheme", {
  pattern = "*",
  callback = function() 
    cmd([[
      highlight clear CursorLine
      highlight Normal ctermbg=none
      highlight LineNr ctermbg=none
      highlight Folded ctermbg=none
      highlight NonText ctermbg=none
      highlight SpecialKey ctermbg=none
      highlight VertSplit ctermbg=none
      highlight SignColumn ctermbg=none
    ]])
  end,
})

vim.api.nvim_create_autocmd("BufWritePost", {
  pattern = "~/.local/share/chezmoi/*",
  command = [[ ! chezmoi apply --source-path % ]],
})

vim.diagnostic.get(0, { severity = {
    vim.diagnostic.severity.ERROR,
    vim.diagnostic.severity.WARN,
} })
vim.diagnostic.config({virtual_text = false, signs = true})

vim.api.nvim_create_autocmd("FileType", {
  pattern = "rust",
  callback = function()
    vim.opt_local.shiftwidth = 4
    vim.opt_local.tabstop = 4
  end
})
