-- (VIM) Remaps Space bar as the Leader command
vim.keymap.set("n", "<leader>pv", vim.cmd.Ex)

--(NAVIGATION)
--Switches to the Left	window
vim.keymap.set("n","<leader>h", ":wincmd h<CR><CR>",{ silent = true })
--Switches to the Bottom window
vim.keymap.set("n","<leader>j", ":wincmd j<CR><CR>",{ silent = true } )
--Switches to the Top window
vim.keymap.set("n","<leader>k", ":wincmd k<CR><CR>",{ silent = true })
--Switches to the Right	window
vim.keymap.set("n","<leader>l", ":wincmd l<CR><CR>",{ silent = true })

--(FILES)
vim.keymap.set("n", "<leader>pf", ":Sex! <bar> :vertical resize 30<CR>")

--(POSITION) 
--[P]ut one line [U]p everything from the cursor till the end of the line 
vim.keymap.set("n","<leader>pu", "d$O<ESC>p")
--[P]ut one line [D]own everything from the cursor till the end of the line 
vim.keymap.set("n","<leader>pd", "d$o<ESC>p")
--Put at then end of the [L]ine [U]pper from the cursor (everything from the cursor till the end of the line) 
vim.keymap.set("n","<leader>lu", "DkA<ESC>p<ESC>jddk<ESC>I<ESC>")
--Put at then end of the [L]ine [D]own(er) from the cursor (everything from the cursor till the end of the line) 
vim.keymap.set("n","<leader>ld", "DjA<ESC>p<ESC>kddj<ESC>I<ESC>")
-- Classic Vim's Windo [U]p and [D]onw controls but keeps the cursor in the middle 
vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<C-u>", "<C-u>zz")
-- Classic Vim's [n]ext and [N]previous controls but keeps the cursor in the middle
vim.keymap.set("n", "n", "nzzzv")
vim.keymap.set("n", "N", "Nzzzv")
-- Mooves what's under the cursor
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv")
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv")

--(COPY PASTE)
-- Copy to your clipboard of your system and not in the internal buffer of vim
vim.keymap.set({"n", "v"}, "<leader>y", [["+y]])
vim.keymap.set("n", "<leader>Y", [["+Y]])

--(WORD) Manipulation
--[W]ord [R]reformat for word under the cursor
-- Replace Madness from the primeagen 
vim.keymap.set("n", "<leader>wr", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])
--[C]hange [W]ord in registered buffer To be more similar to whant vim implment
vim.keymap.set("n","<leader>cw", "ebvey/<C-R>0<CR>Ncw")
--[C]hange [N]ext word in registered buffer To be more similar to what vim implements
vim.keymap.set("n","<leader>cn", "ncw")
--[W]ord [N]ext occurence for word under the cursor
vim.keymap.set("n","<leader>wn", "ebvey/<C-R>0<CR>")
--[W]ord [P]revious occurence for word under the cursor
vim.keymap.set("n","<leader>wp", "ebvey/<C-R>0<CR>NN")
--[W]ord [S]earch for word under the cursor
vim.keymap.set("n","<leader>ws", "ebvey/<C-R>0")
--[W]ord [F]ind [F]irst for word under the cursor
vim.keymap.set("n","<leader>wff", "ebveyG/<C-R>0<CR>", { silent = true })
--[W]ord [F]ind [L]ast for word under the cursor
vim.keymap.set("n","<leader>wfl", "ebveyG/<C-R>0<CR>N",{ silent = true })

--(ADDERS)
--[A]dds a [)] at the end of the line
vim.keymap.set("n","<leader>a)", "A)<ESC>I<ESC>")
--[A]dds a [}] at the end of the line
vim.keymap.set("n","<leader>a}", "A}<ESC>I<ESC>")
--[A]dds a ["]"] at the end of the line
vim.keymap.set("n","<leader>a]", "A]<ESC>I<ESC>")

--(DEBUGER)
vim.keymap.set("n","<leader>db", ":Termdebug <bar> :vertical resize 30<CR>")
vim.keymap.set("n","<leader>ts", ":Step<cr>", { silent = true })
vim.keymap.set("n","<leader>to", ":Over<cr>", { silent = true })
vim.keymap.set("n","<leader>tn", ":Next<cr>", { silent = true })
vim.keymap.set("n","<leader>tc", ":Cont<cr>", { silent = true })
--QUICKFIX Navigation for going to the next errors and so on
vim.keymap.set("n", "<leader>ne", "<cmd>cnext<CR>zz")
vim.keymap.set("n", "<leader>me", "<cmd>cprev<CR>zz")
vim.keymap.set("n", "<leader>nl", "<cmd>lnext<CR>zz")
vim.keymap.set("n", "<leader>ml", "<cmd>lprev<CR>zz")

--(TERMINAL COMMANDS)
-- Makes current file executable
vim.keymap.set("n", "<leader>x", "<cmd>!chmod +x %<CR>", { silent = true })

--SNIPPETS------------------------------------------------------------
--                  Command         Read             template 		                    move cursor 
vim.keymap.set("n","<leader>shs", ":-1read $HOME/.config/nvim/snippets/html_skeleton.html<CR>5jwf>a")
vim.keymap.set("n","<leader>shb", ":-1read $HOME/.config/nvim/snippets/html_vertical_bracets.html<CR>:s/VARTOCHANGE//g<left><left>")
vim.keymap.set("n","<leader>sht", ":-1read $HOME/.config/nvim/snippets/html_horizontal_bracets.html<CR>:.,+2s/VARTOCHANGE//g<left><left>")
vim.keymap.set("n","<leader>scf", ":-1read $HOME/.config/nvim/snippets/c_for.c<CR>yi)/<C-R>0<CR>N:s/VARTOCHANGE//g<left><left>")
vim.keymap.set("n","<leader>scs", ":-1read $HOME/.config/nvim/snippets/c_switch.c<CR>yi)/<C-R>0<CR>Ncw")
vim.keymap.set("n","<leader>scw", ":-1read $HOME/.config/nvim/snippets/c_while.c<CR>yi)/<C-R>0<CR>Ncw")
----------------------------------------------------------------------
