vim.g.mapleader = " "

------ FILE EXPLORER ------- 
vim.keymap.set("n", "<leader>e", vim.cmd.NvimTreeToggle)

------ TEXT WRAPPING -------
vim.keymap.set("n", "<leader>wr", function () vim.opt.wrap = not vim.opt.wrap:get() end)

------- LINE NUMBERS -------
vim.keymap.set("n", "<leader>n", function () vim.opt.nu = not vim.opt.nu:get() end)
vim.keymap.set("n", "<leader>rn", function () vim.opt.relativenumber = not vim.opt.relativenumber:get() end)

------ FIND & REPLACE ------
vim.keymap.set("n", "<leader>rl", function () 
	vim.cmd("s/" .. vim.fn.input("Find & replace on line > ") .. "/g") 
end)

vim.keymap.set("n", "<leader>rf", function ()
	vim.cmd("%s/" .. vim.fn.input("Find & replace in file > ") .. "/g") 
end)

------ SPLIT WINDOWS -------
vim.keymap.set("n", "<leader>vs", vim.cmd.vsplit)
vim.keymap.set("n", "<leader>hs", vim.cmd.split)

vim.keymap.set("n", "<leader>q", vim.cmd.q)

------- TAB BUFFERS --------
vim.keymap.set("n", "<leader>t", vim.cmd.tabnew)

vim.keymap.set("n", "<TAB>", vim.cmd.tabn)

vim.keymap.set("n", "<S-TAB>", vim.cmd.tabp)

------- VIEW WHITESPACE ------
vim.keymap.set("n", "<leader>ws", function() vim.opt.list = not vim.opt.list:get() end)

-------- NVIM TERMINAL -------
vim.keymap.set("n", "<leader>vt", function()
    vim.cmd.vsplit()
    vim.cmd.wincmd('l')
    vim.cmd.terminal()
    vim.cmd.startinsert()
end)

vim.keymap.set("n", "<leader>ht", function()
    vim.cmd.split()
    vim.cmd.wincmd('j')
    vim.cmd.terminal()
    vim.cmd.startinsert()
end)

vim.keymap.set("t", "<Esc>", "<C-\\><C-n>")

------- PLAINTEXT RENDERING -----------
vim.keymap.set("n", "<leader>md", vim.cmd.MarkdownPreviewToggle)



------ SPELL CHECK --------
vim.keymap.set("n", "<leader>sp", function() vim.opt.spell = not vim.opt.spell:get() end)
