-- Don't copy "c" changes to primary register
vim.keymap.set("n", "c", '"_c', { desc = "Prevent copying to primary register" })

-- Move lines up and down
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")

-- Easily open splits
vim.keymap.set("n", "<leader>hs", "<cmd>split<cr>", { desc = "Open horizontal spilt" })
vim.keymap.set("n", "<leader>vs", "<cmd>vsplit<cr>", { desc = "Open vertical spilt" })

-- Easily navigate splits
vim.keymap.set("n", "<A-h>", "<C-w>h", { desc = "Move focus to split left" })
vim.keymap.set("n", "<A-j>", "<C-w>j", { desc = "Move focus to split down" })
vim.keymap.set("n", "<A-k>", "<C-w>k", { desc = "Move focus to split up" })
vim.keymap.set("n", "<A-l>", "<C-w>l", { desc = "Move focus to split right" })

-- Copy the entire file
vim.keymap.set("n", "<leader>y", "ggyG<C-o>", { desc = "Copy the entire file to default register" })

-- Spell-check
vim.keymap.set("n", "<leader>o", "<cmd>setlocal spell! spelllang=en_au<CR>", { desc = "Toggle spell check" })

-- Map Q to nop
vim.keymap.set("n", "Q", "<nop>", { desc = "Remap Q to <nop> because Q is the worst" })

-- Keep highlight when indenting
vim.keymap.set("v", "<", "<gv", { desc = "Keep highlight when indenting" })
vim.keymap.set("v", ">", ">gv", { desc = "Keep highlight when indenting" })

-- Easily navigate tabs
vim.keymap.set("n", "<A-1>", "1gt", { desc = "Navigate to tab 2" })
vim.keymap.set("n", "<A-2>", "2gt", { desc = "Navigate to tab 3" })
vim.keymap.set("n", "<A-3>", "3gt", { desc = "Navigate to tab 4" })
vim.keymap.set("n", "<A-4>", "4gt", { desc = "Navigate to tab 5" })
vim.keymap.set("n", "<A-5>", "5gt", { desc = "Navigate to tab 6" })
vim.keymap.set("n", "<A-6>", "6gt", { desc = "Navigate to tab 7" })
vim.keymap.set("n", "<A-7>", "7gt", { desc = "Navigate to tab 8" })
vim.keymap.set("n", "<A-8>", "8gt", { desc = "Navigate to tab 9" })
vim.keymap.set("n", "<A-9>", "9gt", { desc = "Navigate to tab 10" })

vim.keymap.set("n", "<leader>tN", "<cmd>tabnew<CR>", { desc = "New tab" })
vim.keymap.set("n", "<leader>tn", "<cmd>tabnext<CR>", { desc = "Next tab" })
vim.keymap.set("n", "<leader>tp", "<cmd>tabprevious<CR>", { desc = "Previous tab" })

vim.keymap.set("x", "<leader>p", '"_dP', { desc = "Delete into black hole register" })
vim.keymap.set("n", "<leader>d", '"_d', { desc = "Delete into black hole register" })
vim.keymap.set("v", "<leader>d", '"_d', { desc = "Delete into black hole register" })

-- Keep page scroll centered
vim.keymap.set("n", "<C-d>", "<C-d>zz", { desc = "Scroll down half page" })
vim.keymap.set("n", "<C-u>", "<C-u>zz", { desc = "Scroll up half page" })

-- Keep cursor centered
vim.keymap.set("n", "n", "nzzzv", { desc = "Next search result" })
vim.keymap.set("n", "N", "Nzzzv", { desc = "Previous search result" })

-- Keep cursor centered when jumping through quickfix list
vim.keymap.set("n", "<leader>k", "<cmd>cprev<CR>zz", { desc = "Previous item in quickfix list" })
vim.keymap.set("n", "<leader>j", "<cmd>cnext<CR>zz", { desc = "Next item in quickfix list" })

-- Easily run global search and replace
vim.keymap.set(
	"n",
	"<leader>rr",
	[[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]],
	{ desc = "Search and replace for word under cursor" }
)
