local map = vim.keymap.set map("n", "e", "NvimTreeToggle", { desc = "NvimTree" }) map("n", "f", function() require("conform").format { async = true } end, { desc = "Format buffer" }) map("n", "", "h", { desc = "switch window left" }) map("n", "", "l", { desc = "switch window right" }) map("n", "", "j", { desc = "switch window down" }) map("n", "", "k", { desc = "switch window up" }) map("n", "", "noh", { desc = "general clear highlights" }) map("n", "n", "set nu!", { desc = "toggle line number" }) map("n", "/", "gcc", { desc = "toggle comment", remap = true }) map("v", "/", "gc", { desc = "toggle comment", remap = true }) map("t", "", "", { desc = "terminal escape terminal mode" }) map("n", "th", "ToggleTerm direction=horizontal", { desc = "ToggleTerm: horizontal" }) map("n", "tf", "ToggleTerm direction=float", { desc = "ToggleTerm: float" }) map("n", "", "BufferLineCycleNext", { desc = "Next buffer" }) map("n", "", "BufferLineCyclePrev", { desc = "Previous buffer" }) map("n", "ba", "BufferLineCloseOthers", { desc = "Close other buffers" }) map("n", "x", "BufferLinePickClose", { desc = "Close buffer" }) map("n", "bc", "BufferLinePick", { desc = "Close buffer" }) vim.api.nvim_create_autocmd("LspAttach", { callback = function(ev) local bufnr = ev.buf local opts = function(desc) return { buffer = bufnr, silent = true, desc = desc } end map("n", "gd", vim.lsp.buf.definition, opts "LSP: Go to definition") map("n", "gD", vim.lsp.buf.declaration, opts "LSP: Go to declaration") map("n", "gi", vim.lsp.buf.implementation, opts "LSP: Go to implementation") map("n", "gr", vim.lsp.buf.references, opts "LSP: References") map("n", "K", vim.lsp.buf.hover, opts "LSP: Hover") map("n", "rn", vim.lsp.buf.rename, opts "LSP: Rename") map("n", "ca", vim.lsp.buf.code_action, opts "LSP: Code action") map("n", "[d", function() vim.diagnostic.jump { count = -1, float = true } end, opts "Diag: Prev") map("n", "]d", function() vim.diagnostic.jump { count = 1, float = true } end, opts "Diag: Next") map("n", "dd", vim.diagnostic.open_float, opts "Diag: Line diagnostics") map("n", "lf", function() vim.lsp.buf.format { async = true } end, opts "LSP: Format (server)") end, })