1
0
mirror of https://github.com/dcarrillo/dotfiles.git synced 2024-11-10 08:31:12 +00:00
dotfiles/.config/nvim/lua/core/keymaps.lua

277 lines
7.4 KiB
Lua
Raw Normal View History

2022-10-01 11:46:18 +00:00
-- Shorten function name
local keymap = vim.keymap.set
-- Silent keymap option
local opts = { noremap = true, silent = true }
2022-10-01 11:46:18 +00:00
--Remap space as leader key
keymap("", "<Space>", "<Nop>", opts)
vim.g.mapleader = " "
-- Modes
-- normal_mode = "n",
-- insert_mode = "i",
-- visual_mode = "v",
-- visual_block_mode = "x",
-- term_mode = "t",
-- command_mode = "c",
-- Kitty navigation
vim.g.kitty_navigator_no_mappings = 1
keymap("n", "<A-Left>", ":KittyNavigateLeft<cr>", vim.tbl_extend("force", opts, { desc = "Navigate left" }))
keymap("n", "<A-Down>", ":KittyNavigateDown<cr>", vim.tbl_extend("force", opts, { desc = "Navigate down" }))
keymap("n", "<A-Up>", ":KittyNavigateUp<cr>", vim.tbl_extend("force", opts, { desc = "Navigate up" }))
keymap("n", "<A-Right>", ":KittyNavigateRight<cr>", vim.tbl_extend("force", opts, { desc = "Navigate right" }))
2022-10-01 11:46:18 +00:00
-- Resize with arrows
keymap("n", "<C-Up>", ":resize -2<cr>", vim.tbl_extend("force", opts, { desc = "Window horizontal resize -2" }))
keymap("n", "<C-Down>", ":resize +2<cr>", vim.tbl_extend("force", opts, { desc = "Window horizontal resize +2" }))
keymap(
"n",
"<C-Left>",
":vertical resize -2<cr>",
vim.tbl_extend("force", opts, { desc = "Window vertical resize -2" })
)
keymap(
"n",
"<C-Right>",
":vertical resize +2<cr>",
vim.tbl_extend("force", opts, { desc = "Window vertical resize +2" })
)
2022-10-01 11:46:18 +00:00
-- Navigate buffers
keymap(
"n",
"<C-PageDown>",
":bnext<cr>",
vim.tbl_extend("force", opts, { desc = "Navigate to the next buffer on the right" })
)
keymap(
"n",
"<C-PageUp>",
":bprevious<cr>",
vim.tbl_extend("force", opts, { desc = "Navigate to the previous buffer on the left" })
)
2022-10-01 11:46:18 +00:00
-- Clear highlights
keymap("n", "<leader>h", "<cmd>nohlsearch<cr>", vim.tbl_extend("force", opts, { desc = "Clear search highlights" }))
2022-10-01 11:46:18 +00:00
-- Close buffers
keymap("n", "<S-q>", "<cmd>Bdelete!<cr>", vim.tbl_extend("force", opts, { desc = "Close buffer" }))
2022-10-01 11:46:18 +00:00
2022-11-12 17:39:10 +00:00
-- LSP / Diagnostics
keymap(
"n",
"<leader>xx",
"<cmd>TroubleToggle<cr>",
vim.tbl_extend("force", opts, { desc = "Toggle trouble diganostics" })
)
keymap(
"n",
"<leader>xw",
"<cmd>TroubleToggle workspace_diagnostics<cr>",
vim.tbl_extend("force", opts, { desc = "Toggle trouble workspace diganostics" })
)
keymap(
"n",
"<leader>xd",
"<cmd>TroubleToggle document_diagnostics<cr>",
vim.tbl_extend("force", opts, { desc = "Toggle trouble document diganostics" })
)
keymap(
"n",
"K",
"<cmd>Lspsaga hover_doc<cr>",
vim.tbl_extend("force", opts, { desc = "Show a hover window with the documentation" })
)
keymap(
"n",
"E",
"<cmd>Lspsaga show_line_diagnostics<cr>",
vim.tbl_extend("force", opts, { desc = "Show a hover window with the diagnostics of the error" })
)
keymap(
"n",
"gd",
"<cmd>Lspsaga finder<cr>",
vim.tbl_extend("force", opts, { desc = "Show a hover window with the usage of the directive under the cursor" })
)
keymap(
"n",
"<leader>ld",
"<cmd>Lspsaga goto_definition<cr>",
vim.tbl_extend("force", opts, { desc = "Navigate to the definition of the directive under the cursor" })
)
keymap(
"n",
"<leader>la",
"<cmd>Lspsaga code_action<cr>",
vim.tbl_extend("force", opts, { desc = "Show available code actions for the line under the cursor" })
)
keymap(
"n",
"<leader>lj",
"<cmd>Lspsaga diagnostic_jump_next<cr>",
vim.tbl_extend("force", opts, { desc = "Navigate to the next diagnostic in the buffer" })
)
keymap(
"n",
"<leader>lk",
"<cmd>Lspsaga diagnostic_jump_prev<cr>",
vim.tbl_extend("force", opts, { desc = "Navigate to the previous diagnostic in the buffer" })
)
2023-11-19 15:04:40 +00:00
keymap(
"n",
"<leader>lr",
"<cmd>Lspsaga rename<cr>",
vim.tbl_extend("force", opts, { desc = "Open a dialog to rename a code element" })
)
keymap(
"n",
"<leader>lp",
"<cmd>Lspsaga peek_definition<cr>",
vim.tbl_extend("force", opts, { desc = "Peek the definition of the directive under the cursor" })
)
keymap(
"n",
"<leader>lf",
"<cmd>lua vim.lsp.buf.format{ async=true }<cr>",
vim.tbl_extend("force", opts, { desc = "Format the current buffer or selection" })
)
2022-10-01 11:46:18 +00:00
-- Better paste
keymap("v", "p", "P", vim.tbl_extend("force", opts, { desc = "Paste" }))
2022-10-01 11:46:18 +00:00
-- Press jk fast to enter
keymap("i", "jk", "<ESC>", vim.tbl_extend("force", opts, { desc = "Enter in insert mode" }))
2022-10-01 11:46:18 +00:00
-- Stay in indent mode
keymap("v", "<", "<gv", opts)
keymap("v", ">", ">gv", opts)
-- NeoTree
keymap("n", "<leader>e", ":Neotree toggle<cr>", vim.tbl_extend("force", opts, { desc = "Toggle Neotree" }))
keymap(
"n",
"<leader>gg",
":Neotree float git_status<cr>",
vim.tbl_extend("force", opts, { desc = "Open a float window with the git status" })
)
2022-10-01 11:46:18 +00:00
-- Telescope
keymap(
"n",
"<leader>ff",
":Telescope find_files<cr>",
vim.tbl_extend("force", opts, { desc = "Open a Telescope prompt to search for files" })
)
keymap(
"n",
"<C-p>",
":Telescope find_files<cr>",
vim.tbl_extend("force", opts, { desc = "Open a Telescope prompt to search for files" })
)
keymap(
"n",
"<leader>fg",
":Telescope live_grep<cr>",
vim.tbl_extend("force", opts, { desc = "Open a Telescope prompt to search for text in all files" })
)
keymap(
"n",
"<leader>fk",
":Telescope keymaps<cr>",
vim.tbl_extend("force", opts, { desc = "Open a Telescope prompt to show all keymaps" })
)
keymap(
"n",
"<leader>fc",
":Telescope commands<cr>",
vim.tbl_extend("force", opts, { desc = "Open a Telescope prompt to show all commands" })
)
2022-10-01 11:46:18 +00:00
-- Comment
keymap(
"n",
"<leader>/",
"<cmd>lua require'Comment.api'.toggle.linewise.current()<cr>",
vim.tbl_extend("force", opts, { desc = "Comment/Uncomment code lines" })
)
keymap(
"x",
"<leader>/",
"<esc><cmd>lua require'Comment.api'.toggle.linewise(vim.fn.visualmode())<cr>",
2023-11-19 15:04:40 +00:00
vim.tbl_extend("force", opts, { desc = "Comment/Uncomment code lines on visual block mode" })
)
2023-03-26 10:43:25 +00:00
-- Gitdiff
keymap(
"n",
"<leader>df",
":DiffviewFileHistory %<cr>",
vim.tbl_extend("force", opts, { desc = "Open diff view file history for the current buffer" })
)
keymap("n", "<leader>dc", ":DiffviewClose<cr>", vim.tbl_extend("force", opts, { desc = "Close diff view" }))
2022-10-01 11:46:18 +00:00
-- Projects
keymap(
"n",
"<leader>fp",
":Telescope neovim-project discover<cr>",
vim.tbl_extend("force", opts, { desc = "Open a Telescope prompt to search for projects" })
)
2022-11-09 18:22:40 +00:00
-- Base64
keymap(
"v",
"<leader>64e",
":<c-u>lua require'b64'.encode()<cr>",
vim.tbl_extend("force", opts, { desc = "Encode the visual selected text to base64" })
)
keymap(
"v",
"<leader>64d",
":<c-u>lua require'b64'.decode()<cr>",
vim.tbl_extend("force", opts, { desc = "Decode the visual selected text from base64" })
)
2022-11-12 17:39:10 +00:00
-- Illuminate
keymap(
"n",
"<A-n>",
"<cmd>lua require'illuminate'.next_reference{wrap=true}<cr>",
vim.tbl_extend("force", opts, { desc = "Navigate to the next selected text by illuminate" })
)
keymap(
"n",
"<A-p>",
"<cmd>lua require'illuminate'.next_reference{reverse=true,wrap=true}<cr>",
vim.tbl_extend("force", opts, { desc = "Navigate to the previous selected text by illuminate" })
)
-- Folding
keymap(
"n",
"zR",
"<cmd>lua require'ufo'.openAllFolds()<cr>",
vim.tbl_extend("force", opts, { desc = "Open all folds" })
)
keymap(
"n",
"zM",
"<cmd>lua require'ufo'.closeAllFolds()<cr>",
vim.tbl_extend("force", opts, { desc = "Close all folds" })
)
keymap(
"n",
"zr",
"<cmd>lua require'ufo'.openFoldsExceptKinds()<cr>",
vim.tbl_extend("force", opts, { desc = "Fold less" })
)
keymap("n", "zm", "<cmd>lua require'ufo'.closeFoldsWith()<cr>", vim.tbl_extend("force", opts, { desc = "Fold more" }))
keymap(
"n",
"zp",
"<cmd>lua require'ufo'.peekFoldedLinesUnderCursor()<cr>",
vim.tbl_extend("force", opts, { desc = "Peek fold" })
)