From dc9536eb56abd9882e52a0322e6b75c31381f36e Mon Sep 17 00:00:00 2001 From: "RingOfStorms (Joshua Bell)" Date: Tue, 5 Dec 2023 03:35:17 -0600 Subject: [PATCH] working on keymaps being a bit better --- cspell.json | 2 +- lazy-lock.json | 30 +-- lua/keymaps.lua | 235 ++++++++++-------- lua/plugins/floatterm.lua | 14 +- lua/tools/scratch-files.lua | 2 +- lua/util.lua | 38 ++- .../rust/injections.scm | 2 +- 7 files changed, 193 insertions(+), 130 deletions(-) rename {queries => queries_disabled}/rust/injections.scm (96%) diff --git a/cspell.json b/cspell.json index 116e466..27ec63b 100644 --- a/cspell.json +++ b/cspell.json @@ -1 +1 @@ -{"words":["nvim","builtins","stylua","rustfmt","pendo","tanstack","ripgrep","Typeahead","overscan","autorun","mediatype","BIOINF","Transitioner","pkce","ilike","arrayify","arrayified","komodo","wezterm","gcloud","pbpaste","Hasher","semvers","upserted","dtos","Yeatts","Mahon","Beaubier","Taussing","chakra","langchain","openai","getattr","llms","docstore","kwargs","svgr","healthcheck","venv","virtualenv","ringofstorms","nestjs","oneshot","templating","tiktoken","pydantic","NCCN","clsx","reactflow","Convo","DSAB","pgvector","postprocess","stylelua","sqlx","genemichaels","williamboman","substr","findfile","Hammerspoon","eventtap","OSTYPE","sccache","binstall","elif","autofocus","colours","Resizer","esac","pannable","zoomable","elkjs","Arrayible","Falsey","xyflow","leftnav","topnav","nodrag","nowheel","janky","draghandle","Sandboxed","Dismissable","dashdraw","chrono","serde","rustls","schemars","webserver","concats","deepmerge","Customizer"],"version":"0.2","flagWords":[],"language":"en"} +{"language":"en","version":"0.2","words":["nvim","builtins","stylua","rustfmt","pendo","tanstack","ripgrep","Typeahead","overscan","autorun","mediatype","BIOINF","Transitioner","pkce","ilike","arrayify","arrayified","komodo","wezterm","gcloud","pbpaste","Hasher","semvers","upserted","dtos","Yeatts","Mahon","Beaubier","Taussing","chakra","langchain","openai","getattr","llms","docstore","kwargs","svgr","healthcheck","venv","virtualenv","ringofstorms","nestjs","oneshot","templating","tiktoken","pydantic","NCCN","clsx","reactflow","Convo","DSAB","pgvector","postprocess","stylelua","sqlx","genemichaels","williamboman","substr","findfile","Hammerspoon","eventtap","OSTYPE","sccache","binstall","elif","autofocus","colours","Resizer","esac","pannable","zoomable","elkjs","Arrayible","Falsey","xyflow","leftnav","topnav","nodrag","nowheel","janky","draghandle","Sandboxed","Dismissable","dashdraw","chrono","serde","rustls","schemars","webserver","concats","deepmerge","Customizer","reqwest","brotli","peekable","PDEPO","dotenv","taskserver","walkdir","uuidgen","tolower","nzzzv","tabprevious","tabnext","vsplit","tabclose","tabnew","Neotree","noequalalways","equalalways","bufdo","winnr","keymap","mapleader","maplocalleader","keymaps","setloclist"],"flagWords":[]} diff --git a/lazy-lock.json b/lazy-lock.json index f303c8a..7f11f68 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -1,5 +1,5 @@ { - "LuaSnip": { "branch": "master", "commit": "1def35377854535bb3b0f4cc7a33c083cdb12571" }, + "LuaSnip": { "branch": "master", "commit": "f03089854a8e15594a01562fa7192d0009a6fbe7" }, "auto-save.nvim": { "branch": "main", "commit": "979b6c82f60cfa80f4cf437d77446d0ded0addf0" }, "auto-session": { "branch": "main", "commit": "3eb26b949e1b90798e84926848551046e2eb0721" }, "ccc.nvim": { "branch": "main", "commit": "f77b477d9f0b9a28612212b3fc43145f2a5591cc" }, @@ -8,43 +8,43 @@ "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, "copilot-cmp": { "branch": "master", "commit": "72fbaa03695779f8349be3ac54fa8bd77eed3ee3" }, - "copilot.lua": { "branch": "master", "commit": "3665ed0f3ef3ad68673df7195789d134d0d1fdb0" }, + "copilot.lua": { "branch": "master", "commit": "38a41d0d78f8823cc144c99784528b9a68bdd608" }, "crates.nvim": { "branch": "main", "commit": "1dffccc0a95f656ebe00cacb4de282473430c5a1" }, "diffview.nvim": { "branch": "main", "commit": "3dc498c9777fe79156f3d32dddd483b8b3dbd95f" }, "gitsigns.nvim": { "branch": "main", "commit": "6ef8c54fb526bf3a0bc4efb0b2fe8e6d9a7daed2" }, "glow.nvim": { "branch": "advanced_window", "commit": "f1157d4cb7e46e830c72004e7e1adb81a1f9b04c" }, - "indent-blankline.nvim": { "branch": "master", "commit": "29be0919b91fb59eca9e90690d76014233392bef" }, + "indent-blankline.nvim": { "branch": "master", "commit": "dbd90bb689ff10d21fee6792eb8928f0584b5860" }, "lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" }, "lazygit.nvim": { "branch": "main", "commit": "de35012036d43bca03628d40d083f7c02a4cda3f" }, "lsp-inlayhints.nvim": { "branch": "main", "commit": "d981f65c9ae0b6062176f0accb9c151daeda6f16" }, "lualine.nvim": { "branch": "master", "commit": "2248ef254d0a1488a72041cfb45ca9caada6d994" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "41674c9d50f23cfa3e11f0ca964eb9100c2a8922" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "9453e3d6cd2ca45d96e20f343e8f1b927364b630" }, "mason-null-ls.nvim": { "branch": "main", "commit": "d1f7258f80867f718d643d88eee66959671a4bef" }, "mason.nvim": { "branch": "main", "commit": "41e75af1f578e55ba050c863587cffde3556ffa6" }, "material.nvim": { "branch": "main", "commit": "d61da5decc7768769314c121a3232b6eadc73f2d" }, - "neo-tree.nvim": { "branch": "v2.x", "commit": "20c2f2f5ba083bbb1e37b8bc3d590621434f31e9" }, - "neodev.nvim": { "branch": "main", "commit": "eab4a55c43e0dec631acec992e52490b3f1b5a17" }, - "neogit": { "branch": "master", "commit": "bb538f12fa032c97d4632a6df71d5e0704088139" }, + "neo-tree.nvim": { "branch": "main", "commit": "20c2f2f5ba083bbb1e37b8bc3d590621434f31e9" }, + "neodev.nvim": { "branch": "main", "commit": "1676d2c24186fc30005317e0306d20c639b2351b" }, + "neogit": { "branch": "master", "commit": "f59b0e9648254ccc125e5ddb411711a8438476b3" }, "nerdcommenter": { "branch": "master", "commit": "da948e160d9f54c2967c7927b9c74c5a68c8dc49" }, - "nui.nvim": { "branch": "main", "commit": "257dccc43b4badc735978f0791d216f7d665b75a" }, + "nui.nvim": { "branch": "main", "commit": "1d044afde83e73c56de8e176615a4a6e7c8cf0e3" }, "null-ls.nvim": { "branch": "main", "commit": "0010ea927ab7c09ef0ce9bf28c2b573fc302f5a7" }, "nvim-cmp": { "branch": "main", "commit": "0b751f6beef40fd47375eaf53d3057e0bfa317e4" }, "nvim-early-retirement": { "branch": "main", "commit": "1c89c003e4eeba3ac38482e62d29d66a42549ac6" }, - "nvim-lspconfig": { "branch": "master", "commit": "39546f730bdff8eccf7cec344cfce694f19ac908" }, + "nvim-lspconfig": { "branch": "master", "commit": "cf3dd4a290084a868fac0e2e876039321d57111c" }, "nvim-notify": { "branch": "master", "commit": "e4a2022f4fec2d5ebc79afa612f96d8b11c627b3" }, - "nvim-treesitter": { "branch": "master", "commit": "8f16c39f5b439bd9540336c4d5da705d180e34b9" }, + "nvim-treesitter": { "branch": "master", "commit": "3065a928fc134167f439230b01216e45198be715" }, "nvim-ts-autotag": { "branch": "main", "commit": "6be1192965df35f94b8ea6d323354f7dc7a557e4" }, - "nvim-ts-context-commentstring": { "branch": "main", "commit": "b8ff464f2afc2000f6c72fa331a8fc090cb46b39" }, + "nvim-ts-context-commentstring": { "branch": "main", "commit": "1277b4a1f451b0f18c0790e1a7f12e1e5fdebfee" }, "nvim-web-devicons": { "branch": "master", "commit": "5efb8bd06841f91f97c90e16de85e96d57e9c862" }, "openingh.nvim": { "branch": "main", "commit": "5c9e851d7c26fdb236dfea8866b71fefe7ddeffc" }, "playground": { "branch": "master", "commit": "ba48c6a62a280eefb7c85725b0915e021a1a0749" }, - "plenary.nvim": { "branch": "master", "commit": "366b0837486f60ae0e7550c15de8ff66d057c4cd" }, - "rest.nvim": { "branch": "main", "commit": "235bf4326e3a8a1ee520b939a4452a1a12fbe99b" }, + "plenary.nvim": { "branch": "master", "commit": "55d9fe89e33efd26f532ef20223e5f9430c8b0c0" }, + "rest.nvim": { "branch": "main", "commit": "84e81a19ab24ccf05c9233d34d4dfce61c233abe" }, "rust-tools.nvim": { "branch": "master", "commit": "0cc8adab23117783a0292a0c8a2fbed1005dc645" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "6c921ca12321edaa773e324ef64ea301a1d0da62" }, - "telescope-ui-select.nvim": { "branch": "master", "commit": "c261d903a78c2cda47a5e44488621f10f9dd7fcf" }, + "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "master", "commit": "c1a2af0af69e80e14e6b226d3957a064cd080805" }, - "text-case.nvim": { "branch": "main", "commit": "f854ff31691002c7e6d20868e9a1ac9c93400ee6" }, + "text-case.nvim": { "branch": "main", "commit": "ebe3650101a3505044559f71ec4ea4c789292164" }, "undotree": { "branch": "master", "commit": "36ff7abb6b60980338344982ad4cdf03f7961ecd" }, "vim-floaterm": { "branch": "master", "commit": "3f01a623376957437f9376327637491b74719e38" }, "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" } diff --git a/lua/keymaps.lua b/lua/keymaps.lua index 168e6e3..9807253 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -11,119 +11,136 @@ vim.g.maplocalleader = " " -- term_mode = "t", -- command_mode = "c", +local nvx = { "n", "v", "x" } + require("util").keymaps({ - n = { - [";"] = { ":", desc = "No shift command 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" }, - ["a"] = { "ggVG", desc = "Select all" }, - ["w"] = { "w", desc = "Save" }, - ["qq"] = { - 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 unamed 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", - }, - ["bq"] = { "bp|bd #", desc = "Close current buffer only" }, - ["tn"] = { "tabnew", desc = "Create new tab" }, - ["tq"] = { "tabclose", desc = "Close current tab" }, - ["|"] = { "vsplit", desc = "Vertical Split" }, - ["\\"] = { "split", desc = "Horizontal Split" }, - [""] = { "zz", desc = "Vertical half page down and center cursor" }, - [""] = { "zz", desc = "Vertical half page up and center cursor" }, - ["y"] = { '"+y', desc = "Copy to system clipboard" }, - ["p"] = { '"+p', desc = "Paste from system clipboard" }, - -- ["Q"] = { "Neotree closeqa", desc = "Quit all" }, - ["sq"] = { - "Neotree closeSessionDeleteqa", - desc = "Quit all, no session saved", - }, - -- ["q"] = { "Neotree closeqa", desc = "Quit all" }, - ["Q"] = { "Neotree closeqa", desc = "Quit all" }, - ["J"] = { "mzJ`z", desc = "Move line below onto this line" }, - [""] = { "", desc = "Go back " }, - -- window navigation - [""] = { "h", desc = "Move window left current" }, - [""] = { "j", desc = "Move window below current" }, - [""] = { "k", desc = "Move window above current" }, - [""] = { "l", desc = "Move window right current" }, - -- tab navigation - ["H"] = { "tabprevious", desc = "Move to previous tab" }, - ["L"] = { "tabnext", desc = "Move to next tab" }, - -- reformat LSP - ["l"] = { - function() - -- vim.cmd "SqlxFormat" - vim.lsp.buf.format() - end, - desc = "Reformat file", - }, - ["ls"] = { "SqlxFormat", desc = "Format sqlx queries in rust raw string literals." }, - ["ld"] = { - function() - vim.diagnostic.open_float() - end, - desc = "Show diagnostic message", - }, - ["ll"] = { - function() - vim.diagnostic.setloclist() - end, - desc = "Show diagnostic list", - }, - ["lz"] = { "e", desc = "Edit current file again / Restart LSP Server" }, - [",uu"] = { ':let @u = trim(tolower(system("uuidgen")))au', desc = "Generate and insert UUID" }, - ["B"] = { "b#", desc = "Switch to last buffer" }, - ["S"] = { - "set equalalwaysset noequalalways", - desc = "Equalize/resize screens evenly", - }, + -- ============= + -- 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, }, - v = { - ["J"] = { ":m '>+1gv=gv", desc = "Visually move block down" }, - ["K"] = { ":m '<-2gv=gv", desc = "Visually move block up" }, - [",uu"] = { - 'd:let @u = trim(tolower(system("uuidgen")))iu', - desc = "Generate and replace UUID", - }, - ["y"] = { '"+y', desc = "Copy to system clipboard" }, - ["p"] = { '"+p', desc = "Paste from system clipboard" }, - ["p"] = { '"_dP', desc = "Paste without yanking replaced content" }, - [""] = { '"hy:%s/h//g', desc = "Replace current selection" }, - [">"] = { "> gv", desc = "Indent selection" }, - ["<"] = { "< gv", desc = "Outdent selection" }, + { "Q", "Neotree closeqa", desc = "Quit all", mode = nvx }, + { "Q", "", mode = nvx }, -- don't do normal Q quit + { + "QQ", + "Neotree closeSessionDeleteqa", + desc = "Quit all, no session saved", + mode = nvx, }, - i = { - [""] = { "", desc = "Up" }, - [""] = { "", desc = "Down" }, - [""] = { "", desc = "Left" }, - [""] = { "", desc = "Right" }, - [""] = { "", desc = "End" }, - [""] = { "", desc = "Home" }, + { "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 equalalwaysset noequalalways", + desc = "Equalize/resize screens evenly", + mode = nvx, }, - c = { - [""] = { "", desc = "Left" }, - [""] = { "", desc = "Down" }, - [""] = { "", desc = "Up" }, - [""] = { "", desc = "Right" }, - [""] = { "", desc = "End" }, - [""] = { "", desc = "Home" }, + { "", "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, }, - t = { - [""] = { "", desc = "Escape the terminal" }, + { + "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, + }, + + -- ============= + -- 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" }, }) diff --git a/lua/plugins/floatterm.lua b/lua/plugins/floatterm.lua index 329d6ed..fee4754 100644 --- a/lua/plugins/floatterm.lua +++ b/lua/plugins/floatterm.lua @@ -8,7 +8,17 @@ return { desc = "Run selected as command in float terminal", mode = "v", }, - { "", "FloatermToggle Terminal", desc = "Toggle float terminal" }, - { "", "FloatermNew --disposable", desc = "Toggle disposable float terminal", mode = { "v", "n" } }, + { + "", + "FloatermToggle", + desc = "Toggle float terminal", + mode = { "n", "i", "v", "x", "c", "t" }, + }, + { + "", + "FloatermNew --disposable", + desc = "Toggle disposable float terminal", + mode = { "v", "n", "i", "x", "c" }, + }, }, } diff --git a/lua/tools/scratch-files.lua b/lua/tools/scratch-files.lua index 196344a..1347cd6 100644 --- a/lua/tools/scratch-files.lua +++ b/lua/tools/scratch-files.lua @@ -6,7 +6,7 @@ local scratch = function(extension) vim.cmd("execute 'edit " .. filepath .. "'") end -require("util").keymaps({ +require("util").keymaps_old({ n = { ["fsw"] = { function() diff --git a/lua/util.lua b/lua/util.lua index 814642c..b3c6075 100644 --- a/lua/util.lua +++ b/lua/util.lua @@ -1,6 +1,6 @@ local M = {} -function M.keymaps(mappings) +function M.keymaps_old(mappings) for mode, maps in pairs(mappings) do for keymap, options in pairs(maps) do if options then @@ -20,6 +20,42 @@ function M.keymaps(mappings) end end +-- [1]: (string) lhs (required) +-- [2]: (string|fun()) rhs (optional) +-- mode: (string|string[]) mode (optional, defaults to "n") +-- ft: (string|string[]) filetype for buffer-local keymaps (optional) +-- any other option valid for vim.keymap.set +function M.keymaps(keymaps) + -- is not an array, will pass directly to keymaps + if type(keymaps[1]) == "string" then + M.keymap(keymaps) + else + -- is array will iterate over + for _, keymap in pairs(keymaps) do + M.keymap(keymap) + end + end +end + +function M.keymap(keymap) + local lhs = keymap[1] + local rhs = keymap[2] + local mode = keymap["mode"] or "n" + local opts = {} + for key, value in pairs(keymap) do + if type(key) ~= "number" and key ~= "mode" then + opts[key] = value + end + end + + local status, err = pcall(function() + vim.keymap.set(mode, lhs, rhs, opts) + end) + if not status then + vim.notify("Failed to create keymap: " .. err, 3) + end +end + function M.spread(template) local result = {} for key, value in pairs(template) do diff --git a/queries/rust/injections.scm b/queries_disabled/rust/injections.scm similarity index 96% rename from queries/rust/injections.scm rename to queries_disabled/rust/injections.scm index a042693..30a3cd1 100644 --- a/queries/rust/injections.scm +++ b/queries_disabled/rust/injections.scm @@ -1,4 +1,4 @@ -; ==== SQLX syntax highlighting + ==== SQLX syntax highlighting ; query macro (macro_invocation (scoped_identifier