local function H(H,A,K)vim.keymap.set("\105",H,A,K)end local function A(H,A,K)vim.keymap.set("\110",H,A,K)end local function K(H,A,K)vim.keymap.set("\118",H,A,K)end local function e(H,A,K)vim.keymap.set("\099",H,A,K)end local function f()A("\060\115\112\097\099\101\062","\060\110\111\112\062")K("\060\115\112\097\099\101\062","\060\110\111\112\062")e("\119\033\033","\119 \033\115\117\100\111 \116\101\101 \062\047\100\101\118\047\110\117\108\108 \037")K("\060","\060\103\118")K("\062","\062\103\118")A("\106","\103\106")A("\107","\103\107")A("\036","\103\036")A("\048","\094")A("\110","\110\122\122")A("\078","\078\122\122")A("\042","\042\122\122\096\096")A("\035","\035\122\122")A("\103\042","\103\042\122\122")A("\103\035","\103\035\122\122")A("\060\099-\100\062","\060\099-\100\062\122\122")A("\060\099-\117\062","\060\099-\117\062\122\122")A("\060\099-\102\062","\060\099-\102\062\122\122")A("\060\099-\098\062","\060\099-\098\062\122\122")A("\060\099-\104\062","\060\099-\119\062\104")K("\060\099-\104\062","\060\099-\119\062\104")A("\060\099-\106\062","\060\099-\119\062\106")K("\060\099-\106\062","\060\099-\119\062\106")A("\060\099-\107\062","\060\099-\119\062\107")K("\060\099-\107\062","\060\099-\119\062\107")A("\060\099-\108\062","\060\099-\119\062\108")K("\060\099-\108\062","\060\099-\119\062\108")A("\060\108\101\097\100\101\114\062\060\115\112\097\099\101\062","\060\099\109\100\062\117\112\100\097\116\101\060\099\114\062",{silent=true})A("\103\112","\096\091\118\096\093")A("\060\108\101\097\100\101\114\062\108","\060\099\109\100\062\110\111\104\108\115\101\097\114\099\104\060\099\114\062",{silent=true})H("\106\106","\060\101\115\099\062")H("\107\107","\060\101\115\099\062")A("\060\108\101\097\100\101\114\062\063",function()vim.o.spell=not vim.o.spell end)end f()
-- This module contains basic keymappings

local function imap(key, action, opts)
  vim.keymap.set("i", key, action, opts)
end

local function nmap(key, action, opts)
  vim.keymap.set("n", key, action, opts)
end

local function vmap(key, action, opts)
  vim.keymap.set("v", key, action, opts)
end

local function cmap(key, action, opts)
  vim.keymap.set("c", key, action, opts)
end

local function setup()
  nmap("<space>", "<nop>")
  vmap("<space>", "<nop>")

  -- sudo write
  -- type w!! and it would be converted into sudo tee >/dev/null <CONTENT FILENAME
  cmap("w!!", "w !sudo tee >/dev/null %")

  -- more reasonable indents/unindents
  vmap("<", "<gv")
  vmap(">", ">gv")

  -- wrapline-aware navigation
  nmap("j", "gj")
  nmap("k", "gk")
  nmap("$", "g$")
  nmap("0", "^")

  -- center screen on search operations
  nmap("n", "nzz")
  nmap("N", "Nzz")
  nmap("*", "*zz``")
  nmap("#", "#zz")
  nmap("g*", "g*zz")
  nmap("g#", "g#zz")
  nmap("<c-d>", "<c-d>zz")
  nmap("<c-u>", "<c-u>zz")
  nmap("<c-f>", "<c-f>zz")
  nmap("<c-b>", "<c-b>zz")

  -- split navigation
  nmap("<c-h>", "<c-w>h")
  vmap("<c-h>", "<c-w>h")
  nmap("<c-j>", "<c-w>j")
  vmap("<c-j>", "<c-w>j")
  nmap("<c-k>", "<c-w>k")
  vmap("<c-k>", "<c-w>k")
  nmap("<c-l>", "<c-w>l")
  vmap("<c-l>", "<c-w>l")

  nmap("<leader><space>", "<cmd>update<cr>", { silent = true })

  -- select just pasted
  nmap("gp", "`[v`]")

  -- clear highlight
  nmap("<leader>l", "<cmd>nohlsearch<cr>", { silent = true })

  -- exit insert mode
  imap("jj", "<esc>")
  imap("kk", "<esc>")

  -- spellcheck
  nmap("<leader>?", function()
    vim.o.spell = not vim.o.spell
  end)
end

setup()
