local function map(mode, lhs, rhs, opts) opts = opts or {} opts.silent = opts.silent ~= false if opts.remap and not vim.g.vscode then opts.remap = nil end vim.keymap.set(mode, lhs, rhs, opts) end -- better up/down map({ "n", "x" }, "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) map({ "n", "x" }, "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) -- Move to window using the hjkl keys map("n", "", "h", { desc = "Go to left window", remap = true }) map("n", "", "j", { desc = "Go to lower window", remap = true }) map("n", "", "k", { desc = "Go to upper window", remap = true }) map("n", "", "l", { desc = "Go to right window", remap = true }) -- Resize window using arrow keys map("n", "", "resize +2", { desc = "Increase window height" }) map("n", "", "resize -2", { desc = "Decrease window height" }) map("n", "", "vertical resize -2", { desc = "Decrease window width" }) map("n", "", "vertical resize +2", { desc = "Increase window width" }) -- Move Lines map("n", "", "m .+1==", { desc = "Move down" }) map("n", "", "m .-2==", { desc = "Move up" }) map("i", "", "m .+1==gi", { desc = "Move down" }) map("i", "", "m .-2==gi", { desc = "Move up" }) map("v", "", ":m '>+1gv=gv", { desc = "Move down" }) map("v", "", ":m '<-2gv=gv", { desc = "Move up" }) -- Clear search with map({ "i", "n" }, "", "noh", { desc = "Escape and clear hlsearch" }) -- Clear search, diff update and redraw -- taken from runtime/lua/_editor.lua map( "n", "ur", "nohlsearchdiffupdatenormal! ", { desc = "Redraw / clear hlsearch / diff update" } ) -- https://github.com/mhinz/vim-galore#saner-behavior-of-n-and-n map("n", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next search result" }) map("x", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next search result" }) map("o", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next search result" }) map("n", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev search result" }) map("x", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev search result" }) map("o", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev search result" }) -- Add undo break-points map("i", ",", ",u") map("i", ".", ".u") map("i", ";", ";u") -- save file map({ "i", "x", "n", "s" }, "", "w", { desc = "Save file" }) --keywordprg map("n", "K", "norm! K", { desc = "Keywordprg" }) -- better indenting map("v", "<", "", ">gv") -- new file map("n", "fn", "enew", { desc = "New File" }) -- Toggle NeoTree map("n", "e", "NvimTreeToggle", { desc = "Toggle file explorer" }) -- Telescope map("n", "ff", "Telescope find_files", { desc = "Telescope find files" }) map("n", "fg", "Telescope live_grep", { desc = "Telescope find files" }) map("n", "fb", "Telescope buffers", { desc = "Telescope find files" }) -- LSP map("n", "gl", "lua vim.diagnostic.open_float()", { desc = "Show diagnostics" }) map("n", "gd", "lua vim.lsp.buf.definition()", { desc = "Show diagnostics" }) map("n", "gD", "lua vim.lsp.buf.declaration()", { desc = "Show diagnostics" }) map("n", "K", "lua vim.lsp.buf.hover()", { desc = "Show diagnostics" }) -- Buffers map("n", "", "bn", { desc = "Cycle to next buffer" }) map("n", "", "bp", { desc = "Cycle to previous buffer" }) map("n", "bq", "b#|bd#", { desc = "Close current buffer" }) map("n", "bq", "BufferLineCloseOthers", { desc = "Close all other buffers" })