-- Remap space as leader key vim.keymap.set("", "", "", { silent = true }) vim.g.mapleader = " " vim.g.maplocalleader = " " -- Modes test -- normal_mode = "n", -- insert_mode = "i", -- visual_mode = "v", -- visual_block_mode = "x", -- term_mode = "t", -- command_mode = "c", local nvx = { "n", "v", "x" } require("util").keymaps({ -- ============= -- n/v/x -- ============= { ";", ":", desc = "No shift to enter command mode with semicolon. Alias ; to :", mode = nvx }, { "a", "ggVG", desc = "Select all", mode = nvx }, { "w", ":w", desc = "Save", mode = nvx }, { "q", function() -- Use to have this which always closed and quit ont he last screen: ":confirm q" -- Instead I want this behavior: -- if only 1 screen is open then close all buffers, resulting in a blank unnamed buffer window similar to fresh session -- else if more than 1 screen, confirm q to close that screen -- Check the number of screens if vim.fn.winnr("$") == 1 then -- If only 1 screen is open then close all buffers, resulting in a blank unnamed buffer window similar to fresh session vim.cmd("bufdo bd") vim.cmd("SessionDelete") else -- If more than 1 screen, confirm q to close that screen vim.cmd("confirm q") end end, desc = "Quit", mode = nvx, }, { "Q", ":Neotree close:qa", desc = "Quit all", mode = nvx }, { "Q", "", mode = nvx }, -- don't do normal Q quit { "QQ", ":Neotree close:SessionDelete:qa", desc = "Quit all, no session saved", mode = nvx, }, { "y", '"+y', desc = "Copy to system clipboard", mode = nvx }, { "p", '"+p', desc = "Paste from system clipboard", mode = nvx }, { "bq", ":bp|bd #", desc = "Close current buffer only", mode = nvx }, { "tn", ":tabnew", desc = "Create new tab", mode = nvx }, { "tq", ":tabclose", desc = "Close current tab", mode = nvx }, { "H", ":tabprevious", desc = "Move to previous tab", mode = nvx }, { "L", ":tabnext", desc = "Move to next tab", mode = nvx }, { "|", ":vsplit", desc = "Vertical Split", mode = nvx }, { "\\", ":split", desc = "Horizontal Split", mode = nvx }, { "S", ":set equalalways:set noequalalways", desc = "Equalize/resize screens evenly", mode = nvx, }, { "", "h", desc = "Move window left current", mode = nvx }, { "", "j", desc = "Move window below current", mode = nvx }, { "", "k", desc = "Move window above current", mode = nvx }, { "", "l", desc = "Move window right current", mode = nvx }, { "B", ":b#", desc = "Switch to last buffer", mode = nvx }, { "l", function() -- vim.cmd "SqlxFormat" vim.lsp.buf.format() end, desc = "Reformat file", mode = nvx, }, { "ls", ":SqlxFormat", desc = "Format sqlx queries in rust raw string literals.", mode = nvx, }, { "ld", function() vim.diagnostic.open_float() end, desc = "Show diagnostic message", mode = nvx, }, { "ll", function() vim.diagnostic.setloclist() end, desc = "Show diagnostic list", mode = nvx, }, -- ============= -- normal mode -- ============= { "n", "nzzzv", desc = "Next search result centered" }, { "N", "Nzzzv", desc = "Previous search result centered" }, { "", ":noh", desc = "Clear search on escape" }, { "", ":noh", desc = "Clear search on return" }, { "", "zz", desc = "Vertical half page down and center cursor" }, { "", "zz", desc = "Vertical half page up and center cursor" }, { "J", "mzJ`z", desc = "Move line below onto this line" }, { "", "", desc = "Go back " }, -- ============= -- VISUAL -- ============= { "J", ":m '>+1gv=gv", desc = "Visually move block down", mode = "v", }, { "K", ":m '<-2gv=gv", desc = "Visually move block up", mode = "v", }, { ",uu", 'd:let @u = trim(tolower(system("uuidgen")))iu', desc = "Generate and replace UUID", mode = "v", }, { "p", '"_dP', desc = "Paste without yanking replaced content", mode = "v" }, { "", '"hy:%s/h//g', desc = "Replace current selection", mode = "v" }, { ">", "> gv", desc = "Indent selection", mode = "v" }, { "<", "< gv", desc = "Outdent selection", mode = "v" }, -- ============= -- insert / command -- ============= { "", "", desc = "Up", mode = { "i", "c" } }, { "", "", desc = "Down", mode = { "i", "c" } }, { "", "", desc = "Left", mode = { "i", "c" } }, { "", "", desc = "Right", mode = { "i", "c" } }, { "", "", desc = "End", mode = { "i", "c" } }, { "", "", desc = "Home", mode = { "i", "c" } }, -- ============= -- command -- ============= -- { mode = "c" } -- ============= -- terminal -- ============= { "", "", desc = "Escape the terminal", mode = "t" }, })