-- Basic Options
vim.opt_local.spell = true
vim.bo.expandtab = false
vim.bo.smartindent = false
vim.bo.textwidth = 80
vim.wo.colorcolumn = '80'
vim.bo.spelllang = 'en,es,cjk'
vim.bo.complete = 'kspell'

-- Spellcheck
vim.keymap.set('n', '<F7>', '[s', { silent = true, buffer = true })
vim.keymap.set('n', '<F8>', ']s', { silent = true, buffer = true })
vim.keymap.set('n', '<F9>', 'z=1<CR><CR>', { silent = true, buffer = true })
vim.keymap.set('n', '<F10>', 'z=', { silent = true, buffer = true })
vim.keymap.set('i', '<C-l>', '<C-g>u<Esc>[s1z=`]a<C-g>u', { buffer = true, desc = 'Fix Last Miss-Spelling' })

-- Abbreviations
vim.cmd 'iabbrev <buffer> _- –'
vim.cmd 'iabbrev <buffer> -- —'
vim.cmd 'iabbrev <buffer> << «'
vim.cmd 'iabbrev <buffer> >> »'
vim.cmd 'iabbrev <buffer> __ …'
vim.cmd 'iabbrev <buffer> qq “'
vim.cmd 'iabbrev <buffer> QQ ”'

-- Formatting
vim.api.nvim_create_augroup('Pencil', { clear = true })
vim.api.nvim_create_autocmd('InsertEnter', {
  callback = function()
    vim.bo.formatoptions = 'awt1p'
  end,
  group = 'Pencil',
  buffer = 0,
})
vim.api.nvim_create_autocmd('InsertLeave', {
  callback = function()
    vim.bo.formatoptions = 'wt1p'
  end,
  group = 'Pencil',
  buffer = 0,
})
