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

86 lines
3.6 KiB
Lua
Raw Normal View History

2024-05-24 16:07:28 +03:00
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')
2024-09-01 00:44:34 +03:00
-- 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")
2024-05-24 16:07:28 +03:00
-- 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" })
2024-05-24 16:07:28 +03:00
map(
"n",
"<leader>fsb",
"<cmd>Telescope current_buffer_fuzzy_find<cr>",
2024-05-24 16:07:28 +03:00
{ 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" })
2024-05-24 16:07:28 +03:00
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" })
2024-05-24 16:07:28 +03:00
map(
"n",
"<leader><leader>",
"<cmd>Telescope buffers sort_mru=true sort_lastused=true ignore_current_buffer=true<cr>",
2024-05-24 16:07:28 +03:00
{ 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 }))
2024-05-24 16:07:28 +03:00
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" })
2024-05-24 16:07:28 +03:00
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" })
2024-05-24 16:07:28 +03:00
-- minimap
map("n", "<leader>m", MiniMap.toggle, { desc = "Toggle Minimap" })
2024-05-24 16:07:28 +03:00
-- 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" })
2024-05-24 16:07:28 +03:00
-- whichkey
map("n", "<leader>wK", "<cmd>WhichKey<cr>", { desc = "Whichkey show all keymaps" })