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

88 lines
3.7 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')
map({ "n", "v", "x" }, "<Del>", '"_x')
-- 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")
-- quickfix
map("n", "<M-Down>", "<cmd>cnext<cr>", { desc = "Qui[C]kfix Next" })
map("n", "<M-Up>", "<cmd>cprev<cr>", { desc = "Qui[C]kfix Next" })
-- terminal
map("t", "<ESC>", "<C-\\><C-n>")
-- telescope
local telescope = require("telescope.builtin")
map("n", "<leader>ff", telescope.find_files, { desc = "[F]ind [F]iles" })
map("n", "<leader>fh", telescope.help_tags, { desc = "[F]ind [H]elp" })
map("n", "<leader>fr", telescope.oldfiles, { desc = "[F]ind [R]ecent" })
map("n", "<leader>fsb", telescope.current_buffer_fuzzy_find, { desc = "[F]ind [S]tring in current [B]uffer" })
map("n", "<leader>fsg", telescope.live_grep, { desc = "[F]ind [S]tring [G]lobal" })
map("n", "<leader>fgg", telescope.git_files, { desc = "[F]ind [G]it" })
map("n", "<leader>fgs", telescope.git_status, { desc = "[F]ind [G]it [S]tatus" })
map("n", "<leader>fgh", telescope.git_stash, { desc = "[F]ind [G]it Stas[H]" })
map("n", "<leader>fgc", "<cmd>Telescope git_commits<cr>", { desc = "[F]ind [G]it [C]ommits" })
map("n", "<leader><leader>", function()
telescope.buffers({
sort_mru = true,
sort_lastused = true,
ignore_current_buffer = true,
})
end, { desc = "[ ] Find Buffers" })
-- lsp
map("n", "gd", telescope.lsp_definitions, { desc = "[G]oto [D]efinition" })
map("n", "gr", telescope.lsp_references, { desc = "[G]oto [R]eferences" })
map("n", "gI", telescope.lsp_implementations, { 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", telescope.lsp_dynamic_workspace_symbols, { desc = "[W]orkspace [S]ymbols" })
map("n", "<leader>ds", telescope.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" })