--- Tab mappings --- vim.keymap.set("n", "tn", vim.cmd.tabnew) vim.keymap.set("n", "tq", vim.cmd.tabclose) -- switch tabs with Ctrl+PgUp/Ctrl+PgDwn (default vim mapping) --- Buffer mappings --- -- Center cursorline vim.keymap.set("n", "", "zz") -- Save buffer vim.keymap.set("n", "", function () vim.cmd.write({ mods = { silent = true, }, }) end) -- Cycle buffers vim.keymap.set("n", "", vim.cmd.bnext) vim.keymap.set("n", "", vim.cmd.bprev) --- Navigation --- vim.keymap.set("n", "", "zz") vim.keymap.set("n", "", "zz") vim.keymap.set("n", "n", "nzzzv") vim.keymap.set("n", "N", "Nzzzv") -- nnoremap j v:count ? 'j' : 'gj' -- nnoremap k v:count ? 'k' : 'gk' --- General mappings --- -- yank/put using named register vim.keymap.set({ "n", "x", }, "y", '"+y') vim.keymap.set({ "n", "x", }, "p", '"+p') vim.keymap.set({ "n", "x", }, "P", '"+P') vim.keymap.set({ "n", "x", }, "+", function () vim.fn.setreg("+", vim.fn.getreg('"')) end) -- Allow exiting insert mode in terminal by hitting vim.keymap.set("t", "", "") -- Use :diffput/get instead of normal one to allow staging visual selection vim.keymap.set("n", "dp", vim.cmd.diffput) vim.keymap.set("x", "dp", ":diffput") vim.keymap.set("n", "do", vim.cmd.diffget) vim.keymap.set("x", "do", ":diffget") vim.keymap.set({ "n", "i", }, "", function () if vim.fn.pumvisible() ~= 0 then return "pclose" end for _, winid in pairs(vim.api.nvim_tabpage_list_wins(0)) do if vim.api.nvim_win_get_config(winid).relative ~= "" then return "fclose" end end return "" end, { expr = true, } ) -- Remove default mappings vim.keymap.set("", "", "") vim.keymap.set({ "n", }, "K", "") -- Remove right-click menu items vim.cmd.aunmenu({ "PopUp.-1-", }) vim.cmd.aunmenu({ "PopUp.How-to\\ disable\\ mouse", }) -- Default bindings that are good to know: -- insert mode: -- - indent, see :h i_CTRL-T -- - un-indent, see :h i_CTRL-D -- normal mode: -- - scroll window down lines, see :h CTRL-E -- - scroll window up lines, see :h CTRL-Y -- commands: -- :make - execute makeprg with given args -- :copen - open quickfix list -- :cdo {cmd} - execute {cmd} in each valid entry in the quickfix list. -- works like this: -- :cfirst -- :{cmd} -- :cnext -- :{cmd} -- etc. -- :cn - go to the next error in quickfix list that includes a file name -- :cp - go to the previous error in quickfix list that includes a file name -- :cc [num] - go to the specified error in quickfix list -- @: - repeat last command -- :s/foo/bar/ - substitute the first match of foo with bar in the current line -- :s/foo/bar/g - same as above but for all matches in the current line -- :%s/foo/bar/g - same as above, but for all lines in buffer -- :%s/foo/bar/gc - same as above but asking for confirmation on each match -- :lua << EOF - run a lua snippet using lua-heredoc syntax -- local tbl = {1, 2, 3} -- for k, v in ipairs(tbl) do -- print(v) -- end -- EOF