-- Key mapping

-- Move selected line up/down (this should just be added to default vim)
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")

-- Append next line to current line
vim.keymap.set("n", "J", "mzJ`z")

-- Cycling search results keeps cursor in center
vim.keymap.set("n", "n", "nzzzv")
vim.keymap.set("n", "N", "Nzzzv")

-- Pastes yanked text, but doesn't overwrite yanked register
vim.keymap.set("x", "<leader>p", [["_dP]])

-- Copies to system clipboard
vim.keymap.set({ "n", "v" }, "<leader>y", [["+y]])
vim.keymap.set("n", "<leader>Y", [["+Y]])

-- Remaps C-c to escape (github copilot doesn't like C-c)
vim.keymap.set("i", "<C-c>", "<Esc>")

-- Disables default space keymap
vim.keymap.set({ "n", "v" }, "<Space>", "<Nop>", { silent = true })

-- Remap for dealing with word wrap
vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })

-- Splits
vim.keymap.set("n", "<C-h>", "<C-w>h")
vim.keymap.set("n", "<C-j>", "<C-w>j")
vim.keymap.set("n", "<C-k>", "<C-w>k")
vim.keymap.set("n", "<C-l>", "<C-w>l")

-- Resize splits
vim.keymap.set("n", "<C-Up>", ":resize +2<CR>")
vim.keymap.set("n", "<C-Down>", ":resize -2<CR>")
vim.keymap.set("n", "<C-Left>", ":vertical resize +2<CR>")
vim.keymap.set("n", "<C-Right>", ":vertical resize -2<CR>")

-- Ctrl-Backspace to delete word
vim.keymap.set("i", "<C-BS>", "<C-w>")

-- Open netrw file explorer
-- vim.keymap.set("n", "<leader>pv", vim.cmd.Ex)

-- Switch line endings
vim.api.nvim_set_keymap("n", "<leader>lu", ":edit ++ff=unix<CR>", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "<leader>ld", ":edit ++ff=dos<CR>", { noremap = true, silent = true })
