.dotfiles/.config/nvim/lua/nvwynd/keymaps.lua

87 lines
3.6 KiB
Lua

local map = vim.keymap.set
-- generic
-- prevents selected text we past over to be moved in a registry and override our paste
map("x", "p", '"_dP')
-- prevents the deleted text from going into the registry, use `d` for that
map({ "n", "v", "x" }, "x", '"_d')
-- special delete keybind that will not move the deleted selection in a registry
map({ "n", "v" }, "<leader>d", '"_d')
-- filthy casual save keybind
map({ "n", "i" }, "<C-s>", "<cmd>w<cr>", { desc = "File Save" })
-- easy way to close the current buffer
map("n", "<C-X>", "<cmd>bd!<cr>", { desc = "Close Buffer" })
-- moves the selection up or down using K and J (uppercase)
map("v", "J", ":m '>+1<cr>gv=gv")
map("v", "K", ":m '<-2<cr>gv=gv")
-- terminal
map("t", "<ESC>", "<C-\\><C-n>")
-- telescope
map("n", "<leader>ff", "<cmd>Telescope find_files<cr>", { desc = "[F]ind [F]iles" })
map("n", "<leader>fh", "<cmd>Telescope help_tags<cr>", { desc = "[F]ind [H]elp" })
map("n", "<leader>fr", "<cmd>Telescope oldfiles<cr>", { desc = "[F]ind [R]ecent" })
map(
"n",
"<leader>fsb",
"<cmd>Telescope current_buffer_fuzzy_find<cr>",
{ desc = "[F]ind [S]tring in current [B]uffer" }
)
map("n", "<leader>fsg", "<cmd>Telescope live_grep<cr>", { desc = "[F]ind [S]tring [G]lobal" })
map("n", "<leader>fgg", "<cmd>Telescope git_files<cr>", { desc = "[F]ind [G]it" })
map("n", "<leader>fgs", "<cmd>Telescope git_status<cr>", { desc = "[F]ind [G]it [S]tatus" })
map("n", "<leader>fgc", "<cmd>Telescope git_commits<cr>", { desc = "[F]ind [G]it [C]ommits" })
map(
"n",
"<leader><leader>",
"<cmd>Telescope buffers sort_mru=true sort_lastused=true ignore_current_buffer=true<cr>",
{ desc = "[ ] Find Buffers" }
)
-- lsp
map("n", "gd", "<cmd>Telescope lsp_definitions<cr>", { desc = "[G]oto [D]efinition" })
map("n", "gr", "<cmd>Telescope lsp_references<cr>", { desc = "[G]oto [R]eferences" })
map("n", "gI", "<cmd>Telescope lsp_implementations<cr>", { desc = "[G]oto [I]mplementations" })
map("n", "gD", vim.lsp.buf.declaration, { desc = "[G]oto [D]eclaration" })
map("n", "<S-z>", function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = 0 }))
end, { desc = "Toggle Inlay Hint" })
map("n", "<leader>ca", vim.lsp.buf.code_action, { desc = "[C]ode [A]ction" })
map("n", "<leader>cf", vim.lsp.buf.format, { desc = "[C]ode [F]ormat" })
map("n", "<leader>ws", require("telescope.builtin").lsp_dynamic_workspace_symbols, { desc = "[W]orkspace [S]ymbols" })
map("n", "<leader>ds", require("telescope.builtin").lsp_document_symbols, { desc = "[D]ocument [S]ymbols" })
map("n", "<leader>rn", vim.lsp.buf.rename, { desc = "[R]e[n]ame" })
-- neo-tree
map("n", "<leader>n", "<cmd>Neotree toggle<cr>", { desc = "Toggle Filetree Window" })
map("n", "<leader>e", "<cmd>Neotree focus<cr>", { desc = "Focus Filetree Window" })
-- minimap
map("n", "<leader>m", MiniMap.toggle, { desc = "Toggle Minimap" })
-- comment
-- _ represents the / key here
local comment_api = require("Comment.api")
map({ "n", "i" }, "<C-_>", function()
comment_api.toggle.linewise.current()
end, { desc = "Toggle Comment" })
map("x", "<C-_>", function()
local esc = vim.api.nvim_replace_termcodes("<ESC>", true, false, true)
vim.api.nvim_feedkeys(esc, "nx", false)
comment_api.toggle.linewise(vim.fn.visualmode())
end, { desc = "Toggle Comment" })
-- trouble
map("n", "<leader>td", "<cmd>Trouble diagnostics toggle<cr>", { desc = "[T]rouble [D]iagnostics" })
map(
"n",
"<leader>te",
"<cmd>Trouble diagnostics toggle filter.severity=vim.diagnostic.severity.ERROR<cr>",
{ desc = "[T]rouble [E]rrors" }
)
map("n", "<leader>tt", "<cmd>Trouble todo toggle<cr>", { desc = "[T]rouble [T]odo" })
-- whichkey
map("n", "<leader>wK", "<cmd>WhichKey<cr>", { desc = "Whichkey show all keymaps" })