local map = function(keys, func, desc, mode) mode = mode or "n" vim.keymap.set(mode, keys, func, { desc = desc }) end -- Project view (mini.files) map("pv", function() MiniFiles.open(vim.api.nvim_buf_get_name(0)) end, "Open file explorer") -- Move lines around map("J", ":m '>+1gv=gv", "Move line down", "v") map("", ":m '>+1gv=gv", "Move line down", "v") map("K", ":m '<-2gv=gv", "Move line up", "v") map("", ":m '<-2gv=gv", "Move line up", "v") -- Keep cursor in center throughout operations map("J", "mzJ`z", "Join lines and keep cursor") map("", "zz", "Scroll down and center") map("", "zz", "Scroll up and center") map("n", "nzzzv", "Next search result and center") map("N", "Nzzzv", "Previous search result and center") -- Clipboard operations map("p", '"_dP', "Paste without updating register", "x") map("pc", '"+p', "Paste from system clipboard") map("y", '"+y', "Yank to system clipboard") map("y", '"+y', "Yank to system clipboard", "v") map("Y", '"+Y', "Yank line to system clipboard") map("", '"+pa', "Paste from system clipboard", "i") -- Delete without register map("d", '"_d', "Delete without updating register") map("d", '"_d', "Delete without updating register", "v") -- Disable Q map("Q", "", "Disable Q") -- Formatting map("fo", function() vim.cmd("Format") vim.notify("Formatted file", vim.log.levels.INFO, { title = "Formatting" }) end, "Format file") map("fe", function() vim.cmd("FormatEnable") vim.notify("Enabled auto-format", vim.log.levels.INFO, { title = "Formatting" }) end, "Enable auto-format") map("fd", function() vim.cmd("FormatDisable") vim.notify("Disabled auto-format", vim.log.levels.INFO, { title = "Formatting" }) end, "Disable auto-format") -- Organize Imports map("oi", function() vim.lsp.buf.code_action({ context = { only = { "source.organizeImports" }, diagnostics = vim.diagnostic.get(0), }, apply = true, }) end, "Organize Imports") -- map("l", function() -- local lint = require("lint") -- lint.try_lint() -- end, "Lint file") map("esf", function() vim.cmd("EslintFixAll") end, "Fix ESLint issues") -- Window management map("ws", "s", "Split window horizontally") map("wv", "v", "Split window vertically") map("wh", "h", "Move to left window") map("w", "h", "Move to left window") map("wj", "j", "Move to bottom window") map("w", "j", "Move to bottom window") map("wk", "k", "Move to top window") map("w", "k", "Move to top window") map("wl", "l", "Move to right window") map("w", "l", "Move to right window") map("wq", "q", "Close window") map("wf", "f L", "Open file under cursor in new window") -- Buffer operations map("rf", ":e", "Refresh buffer") map("sf", ":w", "Save file") -- Terminal map("", [[]], "Exit terminal insert mode", "t") -- Close quickfix menu after selecting choice vim.api.nvim_create_autocmd("FileType", { pattern = { "qf" }, command = [[nnoremap :cclose]], }) vim.api.nvim_create_user_command("Cppath", function() local path = vim.fn.expand("%:p") vim.fn.setreg("+", path) vim.notify('Copied "' .. path .. '" to the clipboard!') end, {}) -- Kickstart keymaps vim.keymap.set("n", "q", vim.diagnostic.setloclist, { desc = "Open diagnostic [Q]uickfix list" })