diff --git a/flake.lock b/flake.lock index 53c2949..859ce09 100644 --- a/flake.lock +++ b/flake.lock @@ -58,11 +58,11 @@ ] }, "locked": { - "lastModified": 1738275749, - "narHash": "sha256-PM+cGduJ05EZ+YXulqAwUFjvfKpPmW080mcuN6R1POw=", + "lastModified": 1740208222, + "narHash": "sha256-FqgPcK5BK+Mc4cGBCGz555UsVd/TQK9FvmuamBWu+ZY=", "owner": "nix-community", "repo": "home-manager", - "rev": "a8159195bfaef3c64df75d3b1e6a68d49d392be9", + "rev": "f4a07823a298deff0efb0db30f9318511de7c232", "type": "github" }, "original": { @@ -77,17 +77,14 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1738266384, - "narHash": "sha256-bElFR0jR2qRg0SrwWlm0CJJKGgPRLSoPN1N/26H4DNQ=", - "owner": "LarssonMartin1998", - "repo": "neovim-flake", - "rev": "75c20106d069de3f38b7c0c420e1836ac4681b18", - "type": "github" + "lastModified": 1740225052, + "narHash": "sha256-HZT4TXmTPueIjweb1VZmqdkFHuAeOBN1DuhCirWAFAw=", + "path": "/home/nixos/dev/git/neovim-flake", + "type": "path" }, "original": { - "owner": "LarssonMartin1998", - "repo": "neovim-flake", - "type": "github" + "path": "/home/nixos/dev/git/neovim-flake", + "type": "path" } }, "nix-darwin": { @@ -97,11 +94,11 @@ ] }, "locked": { - "lastModified": 1738277753, - "narHash": "sha256-iyFcCOk0mmDiv4ut9mBEuMxMZIym3++0qN1rQBg8FW0=", + "lastModified": 1739933872, + "narHash": "sha256-UhuvTR4OrWR+WBaRCZm4YMkvjJhZ1KZo/jRjE41m+Ek=", "owner": "LnL7", "repo": "nix-darwin", - "rev": "49b807fa7c37568d7fbe2aeaafb9255c185412f9", + "rev": "6ab392f626a19f1122d1955c401286e1b7cf6b53", "type": "github" }, "original": { @@ -155,11 +152,11 @@ "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1736095716, - "narHash": "sha256-csysw/Szu98QDiA2lhWk9seYOyCebeVEWL89zh1cduM=", + "lastModified": 1740046902, + "narHash": "sha256-Xbhz8eEqBmNpvqaGFbF5JopmfNJccWUr8eExtU/iGX4=", "owner": "nix-community", "repo": "NixOS-WSL", - "rev": "63c3b4ed1712a3a0621002cd59bfdc80875ecbb0", + "rev": "c4f6ae89468939d9fcf1a317c062cf5dd02004ea", "type": "github" }, "original": { @@ -171,11 +168,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1737110817, - "narHash": "sha256-DSenga8XjPaUV5KUFW/i3rNkN7jm9XmguW+qQ1ZJTR4=", + "lastModified": 1740019556, + "narHash": "sha256-vn285HxnnlHLWnv59Og7muqECNMS33mWLM14soFIv2g=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "041c867bad68dfe34b78b2813028a2e2ea70a23c", + "rev": "dad564433178067be1fbdfcce23b546254b6d641", "type": "github" }, "original": { @@ -216,27 +213,27 @@ }, "nixpkgs_4": { "locked": { - "lastModified": 1733384649, - "narHash": "sha256-K5DJ2LpPqht7K76bsxetI+YHhGGRyVteTPRQaIIKJpw=", + "lastModified": 1739624908, + "narHash": "sha256-f84lBmLl4tkDp1ZU5LBTSFzlxXP4926DVW3KnXrke10=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "190c31a89e5eec80dd6604d7f9e5af3802a58a13", + "rev": "a60651b217d2e529729cbc7d989c19f3941b9250", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-24.05", + "ref": "nixos-24.11", "repo": "nixpkgs", "type": "github" } }, "nixpkgs_5": { "locked": { - "lastModified": 1738142207, - "narHash": "sha256-NGqpVVxNAHwIicXpgaVqJEJWeyqzoQJ9oc8lnK9+WC4=", + "lastModified": 1739866667, + "narHash": "sha256-EO1ygNKZlsAC9avfcwHkKGMsmipUk1Uc0TbrEZpkn64=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9d3ae807ebd2981d593cddd0080856873139aa40", + "rev": "73cf49b8ad837ade2de76f87eb53fc85ed5d4680", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index da950d7..9e32cee 100644 --- a/flake.nix +++ b/flake.nix @@ -15,7 +15,8 @@ }; nixos-wsl.url = "github:nix-community/NixOS-WSL/main"; - neovim.url = "github:LarssonMartin1998/neovim-flake"; + # neovim.url = "github:LarssonMartin1998/neovim-flake"; + neovim.url = "path:/home/nixos/dev/git/neovim-flake"; nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew"; }; diff --git a/nix/pkgs/home.nix b/nix/pkgs/home.nix index ae22cb7..2053ed0 100644 --- a/nix/pkgs/home.nix +++ b/nix/pkgs/home.nix @@ -49,6 +49,12 @@ let ] ]; + codelldb = pkgs.runCommand "codelldb" { } '' + mkdir -p $out/bin + cp ${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb $out/bin/codelldb + chmod +x $out/bin/codelldb + ''; + symlinkFiles = builtins.listToAttrs ( map (file: { name = builtins.elemAt file 0; @@ -111,6 +117,8 @@ in lldb nodejs tree-sitter + codelldb + bottom ]; file = symlinkFiles; diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index 5fe2913..0350f70 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -1,47 +1,38 @@ { "arrow.nvim": { "branch": "master", "commit": "5438c977e729a29d96bd54c8da3103154e80dbd1" }, - "auto-session": { "branch": "main", "commit": "021b64ed7d4ac68a37be3ad28d8e1cba5bec582c" }, - "blink.cmp": { "branch": "main", "commit": "1cc3b1a908fbcfd15451c4772759549724f38524" }, - "codecompanion.nvim": { "branch": "main", "commit": "e3c528aab52f32513fdb771e3e27d93efe57e12a" }, + "auto-session": { "branch": "main", "commit": "9c3f977aafb56bd73ba0d082c4dcbdba5666faf3" }, + "blink.cmp": { "branch": "main", "commit": "18b352d12b35bca148427b607098df14b75a218f" }, + "codecompanion.nvim": { "branch": "main", "commit": "dd81bd9176daba9ea507cd0457f662c0a15c001f" }, "codesnap.nvim": { "branch": "main", "commit": "6400480aa6cc366cbd931146c429aaa64680dab9" }, - "copilot.vim": { "branch": "release", "commit": "87038123804796ca7af20d1b71c3428d858a9124" }, + "copilot.vim": { "branch": "release", "commit": "cd7f01009fb7b30e22840cadc4faad88b05c6eef" }, "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, - "dressing.nvim": { "branch": "master", "commit": "3a45525bb182730fe462325c99395529308f431e" }, - "fzf-lua": { "branch": "main", "commit": "6f7249741168c0751356e3b6c5c1e3bade833b6b" }, - "gitsigns.nvim": { "branch": "main", "commit": "76d88f3b584e1f83b2aa51663a32cc6ee8d97eff" }, - "incline.nvim": { "branch": "main", "commit": "16fc9c073e3ea4175b66ad94375df6d73fc114c0" }, - "indent-blankline.nvim": { "branch": "master", "commit": "7a698a1d7ed755af9f5a88733b23ca246ce2df28" }, - "lazy.nvim": { "branch": "main", "commit": "d8f26efd456190241afd1b0f5235fe6fdba13d4a" }, - "leap.nvim": { "branch": "main", "commit": "c6bfb191f1161fbabace1f36f578a20ac6c7642c" }, - "lspsaga.nvim": { "branch": "main", "commit": "7dae6e92c82964a8889d3cd999dfd4f271e3a873" }, - "lua-utils.nvim": { "branch": "main", "commit": "e565749421f4bbb5d2e85e37c3cef9d56553d8bd" }, - "lualine.nvim": { "branch": "master", "commit": "2a5bae925481f999263d6f5ed8361baef8df4f83" }, - "mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" }, - "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, - "mini.diff": { "branch": "main", "commit": "00f072250061ef498f91ed226918c9ec31a416a4" }, - "neogit": { "branch": "master", "commit": "060a625660b2816649d83dbd6c7ab1b4345ea8bc" }, - "neorg": { "branch": "main", "commit": "29993a7bb8279ffa0ba473a3f393daa28c645825" }, + "gitsigns.nvim": { "branch": "main", "commit": "4c40357994f386e72be92a46f41fc1664c84c87d" }, + "incline.nvim": { "branch": "main", "commit": "0eb5b7f6fc6636a4e7b2eb2800b7650fd6d164a2" }, + "lazy.nvim": { "branch": "main", "commit": "e5e9bf48211a13d9ee6c1077c88327c49c1ab4a0" }, + "leap.nvim": { "branch": "main", "commit": "8b826a9fc766bffd14288aee01847cb0d6c6c383" }, + "lspsaga.nvim": { "branch": "main", "commit": "4acafaf3455c57c94400e961636d979fb6ddd9fc" }, + "lualine.nvim": { "branch": "master", "commit": "f4f791f67e70d378a754d02da068231d2352e5bc" }, + "markview.nvim": { "branch": "main", "commit": "f1e2a57388b61fff8e9d7519ce05cee27a59a57e" }, + "neogit": { "branch": "master", "commit": "63124cf520ff24d09deb3b850e053908ab0fc66a" }, "neovim-ayu": { "branch": "master", "commit": "283badaa983234c90e857c12c1f1c18e1544360a" }, - "noice.nvim": { "branch": "main", "commit": "eaed6cc9c06aa2013b5255349e4f26a6b17ab70f" }, + "noice.nvim": { "branch": "main", "commit": "0427460c2d7f673ad60eb02b35f5e9926cf67c59" }, "nui.nvim": { "branch": "main", "commit": "53e907ffe5eedebdca1cd503b00aa8692068ca46" }, "nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" }, - "nvim-dap": { "branch": "master", "commit": "99807078c5089ed30e0547aa4b52c5867933f426" }, - "nvim-dap-go": { "branch": "main", "commit": "1bacf2fa7d4dc6a8a4f6cc390f1544e5b34c35a4" }, + "nvim-dap": { "branch": "master", "commit": "6e0e8ab4d8ed520076971465a4388dfe54a91d83" }, + "nvim-dap-go": { "branch": "main", "commit": "8763ced35b19c8dc526e04a70ab07c34e11ad064" }, "nvim-dap-python": { "branch": "master", "commit": "34282820bb713b9a5fdb120ae8dd85c2b3f49b51" }, "nvim-dap-repl-highlights": { "branch": "master", "commit": "a7512fc0a0de0c0be8d58983939856dda6f72451" }, - "nvim-dap-ui": { "branch": "master", "commit": "727c032a8f63899baccb42a1c26f27687e62fc5e" }, + "nvim-dap-ui": { "branch": "master", "commit": "bc81f8d3440aede116f821114547a476b082b319" }, "nvim-dap-virtual-text": { "branch": "master", "commit": "df66808cd78b5a97576bbaeee95ed5ca385a9750" }, - "nvim-nio": { "branch": "master", "commit": "a428f309119086dc78dd4b19306d2d67be884eee" }, - "nvim-notify": { "branch": "master", "commit": "a3020c2cf4dfc4c4f390c4a21e84e35e46cf5d17" }, - "nvim-surround": { "branch": "main", "commit": "9f0cb495f25bff32c936062d85046fbda0c43517" }, - "nvim-treesitter": { "branch": "master", "commit": "984214ef8e4ca18d77639663319aabdfba89632f" }, - "nvim-treesitter-context": { "branch": "master", "commit": "d0dd7ce5a9d0be1f28086e818e52fdc5c78975df" }, + "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, + "nvim-surround": { "branch": "main", "commit": "ae298105122c87bbe0a36b1ad20b06d417c0433e" }, + "nvim-treesitter": { "branch": "master", "commit": "5774e7d3da4f681296a87fcd85d17779ad362a4f" }, + "nvim-treesitter-context": { "branch": "master", "commit": "198720b4016af04c9590f375d714d5bf8afecc1a" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "ad8f0a472148c3e0ae9851e26a722ee4e29b1595" }, - "nvim-web-devicons": { "branch": "master", "commit": "aafa5c187a15701a7299a392b907ec15d9a7075f" }, - "pathlib.nvim": { "branch": "main", "commit": "57e5598af6fe253761c1b48e0b59b7cd6699e2c1" }, + "nvim-web-devicons": { "branch": "master", "commit": "1020869742ecb191f260818234517f4a1515cfe8" }, "persistent-breakpoints.nvim": { "branch": "main", "commit": "4b199b1dcfd136cac8b0fa9c8dbbdeb81463f7a9" }, - "plenary.nvim": { "branch": "master", "commit": "3707cdb1e43f5cea73afb6037e6494e7ce847a66" }, - "rustaceanvim": { "branch": "master", "commit": "0a1876b970ab946be3f4d341e9d743a5d62d646a" }, - "tiny-inline-diagnostic.nvim": { "branch": "main", "commit": "5922bb3dd691a2a37bd51e20d4a3dc7895221e51" }, + "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, + "rustaceanvim": { "branch": "master", "commit": "f03035fa03ccb36cd26d0792c946fbacba1d1a39" }, + "snacks.nvim": { "branch": "main", "commit": "b100c937177536cf2aa634ddd2aa5b8a1dd23ace" }, "vim-repeat": { "branch": "master", "commit": "65846025c15494983dafe5e3b46c8f88ab2e9635" } } diff --git a/nvim/lua/dap/adapters/codelldb.lua b/nvim/lua/dap/adapters/codelldb.lua index d193344..3c6484a 100644 --- a/nvim/lua/dap/adapters/codelldb.lua +++ b/nvim/lua/dap/adapters/codelldb.lua @@ -2,7 +2,7 @@ return { type = "server", port = "${port}", executable = { - command = vim.fn.exepath("codelldb"), -- Update with your codelldb binary path + command = vim.fn.exepath("codelldb"), args = { "--port", "${port}" }, }, } diff --git a/nvim/lua/format_handler.lua b/nvim/lua/format_handler.lua index 367c77f..fc539af 100644 --- a/nvim/lua/format_handler.lua +++ b/nvim/lua/format_handler.lua @@ -26,18 +26,10 @@ function M.setup() vim.api.nvim_command("command! " .. cmd[1] .. " " .. cmd[2]) end - utils.add_keymaps({ - n = { - ["ff"] = { - cmd = function() M.format(true) end - }, - ["fe"] = { - cmd = M.format_enable, - }, - ["fd"] = { - cmd = M.format_disable, - }, - }, + utils.set_keymap_list({ + { "ff", function() M.format() end }, + { "fe", function() M.format_enable() end }, + { "fd", function() M.format_disable() end }, }) end diff --git a/nvim/lua/keymaps.lua b/nvim/lua/keymaps.lua index f3d871e..236ec9a 100644 --- a/nvim/lua/keymaps.lua +++ b/nvim/lua/keymaps.lua @@ -1,151 +1,98 @@ +local utils = require("utils") local g = vim.g g.mapleader = " " g.maplocalleader = " " -local move_up = { - cmd = "v:count || mode(1)[0:1] == \"no\" ? \"k\" : \"gk\"", - opts = { - expr = true - } -} +local move_up = { "v:count || mode(1)[0:1] == \"no\" ? \"k\" : \"gk\"", { expr = true } } +local move_down = { "v:count || mode(1)[0:1] == \"no\" ? \"j\" : \"gj\"", { expr = true } } -local move_down = { - cmd = "v:count || mode(1)[0:1] == \"no\" ? \"j\" : \"gj\"", - opts = { - expr = true - } -} +utils.foreach({ + { + "n", + { + -- Using lspsaga for hover doc + { "K", "", }, + -- Using lspsaga finder with gr which does references + { "grr", "", }, + { "gra", "", }, + { "grn", "", }, + { "gri", "", }, + -- Navigation + { "", "h", }, + { "", "j", }, + { "", "k", }, + { "", "l", }, + { "", "h", }, + { "", "j", }, + { "", "k", }, + { "", "l", }, + -- Window + { "", "q", }, -local utils = require("utils") + -- Disable current highlights + { "", " noh ", }, -utils.add_keymaps({ - n = { - -- Using lspsaga for hover doc - ["K"] = { - cmd = "", - }, - -- Using lspsaga finder with gr which does references - ["grr"] = { - cmd = "", - }, - ["gra"] = { - cmd = "", - }, - ["grn"] = { - cmd = "", - }, - ["gri"] = { - cmd = "", - }, - -- Navigation - [""] = { - cmd = "h", - }, - [""] = { - cmd = "j", - }, - [""] = { - cmd = "k", - }, - [""] = { - cmd = "l", - }, - [""] = { - cmd = "h", - }, - [""] = { - cmd = "j", - }, - [""] = { - cmd = "k", - }, - [""] = { - cmd = "l", - }, + -- Copies the entire file + { "", ":%y+", { silent = true } }, - -- Window - [""] = { - cmd = "q", - }, + -- Allow moving the cursor through wrapped lines with and + -- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ + -- empty mode is same as using :map + -- also don't use g[j|k] when in operator pending mode, + -- so it doesn't alter d, y or c behaviour + { "", move_up[1], move_up[2], }, + { "", move_down[1], move_down[2], }, + { "j", move_down[1], move_down[2], }, + { "k", move_up[1], move_up[2], }, + -- Maps to remove + { "", "", }, - -- Disable current highlights - [""] = { - cmd = " noh ", - }, - - -- Copies the entire file - [""] = { - cmd = ":%y+", - opts = { - silent = true - } - }, - - -- Allow moving the cursor through wrapped lines with and - -- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ - -- empty mode is same as using :map - -- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour - [""] = move_up, - [""] = move_down, - ["j"] = move_down, - ["k"] = move_up, - -- Maps to remove - [""] = { - cmd = "", - }, - - -- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation. - -- Prioritize regular m for leaping, and m for setting marks. - ["m"] = { - cmd = "m", - }, - ["[d"] = { - cmd = function() + -- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation. + -- Prioritize regular m for leaping, and m for setting marks. + { "m", "m", }, + { "[d", function() vim.diagnostic.jump({ count = -1, float = false }) - end - }, - ["]d"] = { - cmd = function() + end }, + { "]d", function() vim.diagnostic.jump({ count = 1, float = false }) - end - }, + end }, + } }, - i = {}, - v = { - [""] = move_up, - [""] = move_down, - ["j"] = move_down, - ["k"] = move_up, - [""] = { - cmd = ">gv", - }, - [""] = { - cmd = "", move_up[1], move_up[2], }, + { "", move_down[1], move_down[2], }, + { "j", move_down[1], move_down[2], }, + { "k", move_up[1], move_up[2], }, + { "", ">gv", }, + { "", "m for setting marks. - ["m"] = { - cmd = "m", + -- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation. + -- Prioritize regular m for leaping, and m for setting marks. + { "m", "m", }, }, }, - x = { - [""] = move_up, - [""] = move_down, - ["j"] = move_down, - ["k"] = move_up, - ["p"] = { - cmd = "p:let @+=@0:let @\"=@0", - opts = { - silent = true - }, - }, + { + "x", + { + { "", move_up[1], move_up[2], }, + { "", move_down[1], move_down[2], }, + { "j", move_down[1], move_down[2], }, + { "k", move_up[1], move_up[2], }, + { "p", "p:let @+=@0:let @\"=@0", { silent = true }, }, + } }, - t = { - [""] = { - cmd = "", - }, + { + "t", + { + { "", "", }, + } }, -}) +}, function(mode_mapping) + local mode = mode_mapping[1] + local mappings = mode_mapping[2] + utils.set_keymap_list(mappings, mode) +end) diff --git a/nvim/lua/lsp/servers/clangd.lua b/nvim/lua/lsp/servers/clangd.lua index 45d55ce..f242c06 100644 --- a/nvim/lua/lsp/servers/clangd.lua +++ b/nvim/lua/lsp/servers/clangd.lua @@ -1,21 +1,23 @@ local utils = require("utils") -- https://clangd.llvm.org/extensions.html#switch-between-sourceheader -local function switch_source_header(bufnr) - bufnr = utils.validate_bufnr(bufnr) +local function switch_source_header() + local bufnr = utils.validate_bufnr(0) local clangd_client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd" })[1] - local params = { uri = vim.uri_from_bufnr(bufnr) } if clangd_client then - clangd_client.request("textDocument/switchSourceHeader", params, function(err, result) - if err then - error(tostring(err)) - end - if not result then - print "Corresponding file cannot be determined" - return - end - vim.api.nvim_command("drop " .. vim.uri_to_fname(result)) - end, bufnr) + clangd_client.request( + "textDocument/switchSourceHeader", + { uri = vim.uri_from_bufnr(bufnr) }, + function(err, result) + if err then + error(tostring(err)) + end + if not result then + print "Corresponding file cannot be determined" + return + end + vim.api.nvim_command("drop " .. vim.uri_to_fname(result)) + end, bufnr) else print "method textDocument/switchSourceHeader is not supported by any servers active on the current buffer" end @@ -44,19 +46,9 @@ return { "compile_flags.txt", "configure.ac", }, - on_attach = function(_, bufnr) - local lsp_maps = { - { - "ko", - function() switch_source_header(0) end, - }, - } - - local keymaps = { n = {} } - for i, _ in ipairs(lsp_maps) do - local binding, cmd = unpack(lsp_maps[i]) - keymaps.n[binding] = { cmd = cmd, opts = { buffer = bufnr } } - end - utils.add_keymaps(keymaps) + on_attach = function() + utils.set_keymap_list({ + { "ko", switch_source_header, }, + }) end, } diff --git a/nvim/lua/lsp/setup.lua b/nvim/lua/lsp/setup.lua index 73f85b5..9192cfc 100644 --- a/nvim/lua/lsp/setup.lua +++ b/nvim/lua/lsp/setup.lua @@ -24,34 +24,9 @@ local function global_on_attach(client, bufnr) }) end - utils.add_keymaps({ - n = { - - ["gd"] = { - cmd = function() - vim.lsp.buf.definition({ - reuse_win = true, - }) - end, - opts = { - noremap = true, - silent = true, - buffer = bufnr - } - }, - ["gD"] = { - cmd = function() - vim.lsp.buf.declaration({ - reuse_win = true, - }) - end, - opts = { - noremap = true, - silent = true, - buffer = bufnr - } - }, - } + utils.set_keymap_list({ + { "gd", function() vim.lsp.buf.definition({ reuse_win = true, }) end, { noremap = true, buffer = bufnr } }, + { "gD", function() vim.lsp.buf.declaration({ reuse_win = true, }) end, { noremap = true, buffer = bufnr } }, }) end diff --git a/nvim/lua/plugs/auto_session.lua b/nvim/lua/plugs/auto_session.lua index 488905d..660f348 100644 --- a/nvim/lua/plugs/auto_session.lua +++ b/nvim/lua/plugs/auto_session.lua @@ -11,7 +11,6 @@ return { "~/Dev", "~/Dev/Git", "~/.config", - "~/dev/git/.dotfiles", }, }, init = function() diff --git a/nvim/lua/plugs/codecompanion.lua b/nvim/lua/plugs/codecompanion.lua index 033cf67..8966ae2 100644 --- a/nvim/lua/plugs/codecompanion.lua +++ b/nvim/lua/plugs/codecompanion.lua @@ -3,53 +3,37 @@ return { dependencies = { "nvim-lua/plenary.nvim", "nvim-treesitter/nvim-treesitter", - { 'echasnovski/mini.diff', version = false }, - { "stevearc/dressing.nvim", opts = {} }, }, - config = function() - require("codecompanion").setup({ - strategies = { - chat = { - adapter = "copilot", - }, - inline = { - adapter = "copilot", - }, - agent = { - adapter = "copilot", - }, + opts = { + strategies = { + chat = { + adapter = "copilot", }, - adapters = { - copilot = function() return require("codecompanion.adapters").extend("copilot", {}) end, + inline = { + adapter = "copilot", }, - display = { - diff = { - provider = "mini_diff", - }, + agent = { + adapter = "copilot", }, - opts = { - log_level = "DEBUG", + }, + adapters = { + copilot = function() return require("codecompanion.adapters").extend("copilot", {}) end, + }, + display = { + diff = { + provider = "mini_diff", }, - }) - - local keymaps = { - n = { - ["ci"] = { cmd = "CodeCompanion" }, - ["cc"] = { cmd = "CodeCompanionChat toggle" }, - ["cm"] = { cmd = "CodeCompanion /commit" }, - }, - v = { - ["ci"] = { cmd = "CodeCompanion" }, - ["ga"] = { cmd = "CodeCompanionAdd" }, - ["ce"] = { cmd = "CodeCompanion /explain" }, - ["cf"] = { cmd = "CodeCompanion /fix" }, - ["ct"] = { cmd = "CodeCompanion /tests" }, - } - } - local utils = require("utils") - utils.add_opts_to_all_mappings(keymaps, { silent = true }) - utils.add_keymaps(keymaps) - + }, + opts = { + log_level = "DEBUG", + }, + }, + keys = { + { "ci", "CodeCompanion" }, + { "cc", "CodeCompanionChat toggle" }, + { "ce", "CodeCompanion /explain", mode = "v" }, + }, + init = function() vim.cmd([[cab cc CodeCompanion]]) end } diff --git a/nvim/lua/plugs/codesnap.lua b/nvim/lua/plugs/codesnap.lua index 0966981..042e834 100644 --- a/nvim/lua/plugs/codesnap.lua +++ b/nvim/lua/plugs/codesnap.lua @@ -3,24 +3,16 @@ return { build = "make", event = "VeryLazy", lazy = true, - config = function() - require("codesnap").setup({ - mac_window_bar = true, - title = "codesnap.nvim", - code_font_family = "JetBrainsMono Nerd Font", - breadcrumbs_separator = "/", - has_breadcrumbs = true, - bg_theme = "grape", - watermark = "", - }) - - require("utils").add_keymaps({ - v = { - ["cs"] = { - cmd = ":CodeSnap", - opts = { silent = true }, - }, - } - }) - end, + opts = { + mac_window_bar = true, + title = "codesnap.nvim", + code_font_family = "JetBrainsMono Nerd Font", + breadcrumbs_separator = "/", + has_breadcrumbs = true, + bg_theme = "grape", + watermark = "", + }, + keys = { + { "cs", ":CodeSnap", mode = "v", silent = true, noremap = true }, + }, } diff --git a/nvim/lua/plugs/copilot.lua b/nvim/lua/plugs/copilot.lua index d3feadd..01d381a 100644 --- a/nvim/lua/plugs/copilot.lua +++ b/nvim/lua/plugs/copilot.lua @@ -1,18 +1,18 @@ return { "github/copilot.vim", - config = function() + event = "InsertEnter", + init = function() vim.g.copilot_no_tab_map = true - require("utils").add_keymaps({ - i = { - [""] = { - cmd = 'copilot#Accept("\\")', - opts = { - expr = true, - replace_keycodes = false, - silent = true, - } - } - } - }) - end + end, + keys = { + { + "", + 'copilot#Accept("\\")', + mode = "i", + expr = true, + replace_keycodes = false, + silent = true, + desc = "Copilot Accept with ", + }, + }, } diff --git a/nvim/lua/plugs/incline.lua b/nvim/lua/plugs/incline.lua index 3557bf1..081dfa0 100644 --- a/nvim/lua/plugs/incline.lua +++ b/nvim/lua/plugs/incline.lua @@ -1,95 +1,86 @@ return { "b0o/incline.nvim", dependencies = { - "lewis6991/gitsigns.nvim" + { + "lewis6991/gitsigns.nvim", + opts = {}, + keys = { + { "[g", function() require("gitsigns").nav_hunk("prev") end, }, + { "]g", function() require("gitsigns").nav_hunk("next") end, }, + } + } }, event = "VeryLazy", lazy = true, - config = function() - local gitsigns = require("gitsigns") - gitsigns.setup({}) - local devicons = require("nvim-web-devicons") - require("incline").setup({ - window = { - padding = 0, - }, - hide = { - cursorline = true, - }, - render = function(props) - local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(props.buf), ":t") - if filename == "" then - filename = "[No Name]" - end - local ft_icon, ft_color = devicons.get_icon_color(filename) + opts = { + window = { + padding = 0, + }, + hide = { + cursorline = true, + }, + render = function(props) + local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(props.buf), ":t") + if filename == "" then + filename = "[No Name]" + end + local ft_icon, ft_color = require("nvim-web-devicons").get_icon_color(filename) - local function get_git_diff() - local icons = { removed = "", changed = "", added = "" } - local signs = vim.b[props.buf].gitsigns_status_dict - local labels = {} - if signs == nil then - return labels - end - for name, icon in pairs(icons) do - if tonumber(signs[name]) and signs[name] > 0 then - table.insert(labels, { icon .. " " .. signs[name] .. " ", group = "Diff" .. name }) - end - end - if #labels > 0 then - table.insert(labels, { "┊ " }) - end + local function get_git_diff() + local icons = { removed = "", changed = "", added = "" } + local signs = vim.b[props.buf].gitsigns_status_dict + local labels = {} + if signs == nil then return labels end - - local function get_diagnostic_label() - local icons = { error = "", warn = "", info = "", hint = "" } - local label = {} - - for severity, icon in pairs(icons) do - local n = #vim.diagnostic.get(props.buf, - { severity = vim.diagnostic.severity[string.upper(severity)] }) - if n > 0 then - table.insert(label, { icon .. " " .. n .. " ", group = "DiagnosticSign" .. severity }) - end + for name, icon in pairs(icons) do + if tonumber(signs[name]) and signs[name] > 0 then + table.insert(labels, { icon .. " " .. signs[name] .. " ", group = "Diff" .. name }) end - if #label > 0 then - table.insert(label, { "┊ " }) + end + if #labels > 0 then + table.insert(labels, { "┊ " }) + end + return labels + end + + local function get_diagnostic_label() + local icons = { error = "", warn = "", info = "", hint = "" } + local label = {} + + for severity, icon in pairs(icons) do + local n = #vim.diagnostic.get(props.buf, + { severity = vim.diagnostic.severity[string.upper(severity)] }) + if n > 0 then + table.insert(label, { icon .. " " .. n .. " ", group = "DiagnosticSign" .. severity }) end - return label + end + if #label > 0 then + table.insert(label, { "┊ " }) + end + return label + end + + local function get_arrow_label() + local statusline = require("arrow.statusline") + if statusline.is_on_arrow_file(props.buf) == nil then + return "" end - local function get_arrow_label() - local statusline = require("arrow.statusline") - if statusline.is_on_arrow_file(props.buf) == nil then - return "" - end + return " " .. statusline.text_for_statusline_with_icons(props.buf) + end - return " " .. statusline.text_for_statusline_with_icons(props.buf) - end - - return { - guibg = "#1e2030", - guifg = "#cad3f5", - { " " }, - { get_diagnostic_label() }, - { get_git_diff() }, - { (ft_icon or "") .. " ", guifg = ft_color, guibg = "none" }, - { filename .. " ┊", gui = vim.bo[props.buf].modified and "bold,italic" or "bold" }, - { get_arrow_label() .. "  " .. vim.api.nvim_win_get_number(props.win), group = "DevIconWindows" }, - { " " } - } - end, - - require("utils").add_keymaps({ - n = { - ["[g"] = { - cmd = function() gitsigns.nav_hunk("prev") end - }, - ["]g"] = { - cmd = function() gitsigns.nav_hunk("next") end - } - } - }) - }) - end, + return { + guibg = "#1e2030", + guifg = "#cad3f5", + { " " }, + { get_diagnostic_label() }, + { get_git_diff() }, + { (ft_icon or "") .. " ", guifg = ft_color, guibg = "none" }, + { filename .. " ┊", gui = vim.bo[props.buf].modified and "bold,italic" or "bold" }, + { get_arrow_label() .. "  " .. vim.api.nvim_win_get_number(props.win), group = "DevIconWindows" }, + { " " } + } + end, + }, } diff --git a/nvim/lua/plugs/leap.lua b/nvim/lua/plugs/leap.lua index 1fe86c4..76ca034 100644 --- a/nvim/lua/plugs/leap.lua +++ b/nvim/lua/plugs/leap.lua @@ -1,3 +1,15 @@ +local function leap_across_windows() + require("leap").leap({ + target_windows = require("leap.user").get_focusable_windows() + }) +end + +local function leap_in_current_buffer() + require("leap").leap({ + target_windows = { vim.api.nvim_get_current_win() } + }) +end + local saved_hlsearch = false local saved_highlights = {} local colors = require("ayu.colors") @@ -19,7 +31,13 @@ return { }, event = "VeryLazy", lazy = true, - config = function() + opts = {}, + keys = { + { "m", function() leap_across_windows() end, mode = "n" }, + { "m", function() leap_in_current_buffer() end, mode = "v" }, + { "m", function() leap_in_current_buffer() end, mode = "o" }, + }, + init = function() local leap = require("leap") -- Disable auto jumping to the first match @@ -53,42 +71,5 @@ return { for _, cmd in ipairs(autocmds) do utils.create_user_event_cb(cmd.event_name, cmd.cb, leap_augroup_name) end - - local leap_user = require("leap.user") - local function leap_across_windows() - leap.leap({ - target_windows = leap_user.get_focusable_windows() - }) - end - - local function leap_in_current_buffer() - leap.leap({ - target_windows = { vim.api.nvim_get_current_win() } - }) - end - - utils.add_keymaps({ - n = { - ["m"] = { - cmd = function() - leap_across_windows() - end, - }, - }, - v = { - ["m"] = { - cmd = function() - leap_in_current_buffer() - end, - } - }, - o = { - ["m"] = { - cmd = function() - leap_in_current_buffer() - end, - } - } - }) end, } diff --git a/nvim/lua/plugs/lspsaga.lua b/nvim/lua/plugs/lspsaga.lua index f5f9578..54e23bb 100644 --- a/nvim/lua/plugs/lspsaga.lua +++ b/nvim/lua/plugs/lspsaga.lua @@ -7,59 +7,36 @@ return { dependencies = { "nvim-tree/nvim-web-devicons", }, - after = "nvim-lspconfig", - config = function() - require("lspsaga").setup({ - request_timeout = 750, - symbol_in_winbar = { - enable = false, - }, - implement = { - enable = false, - }, - outline = { - enable = false, - win_width = 52, - }, - ui = { - border = "rounded", - title = false, - }, - code_action = { - extend_gitsigns = true - }, - hover = { - jump_on_first_press = true - }, - }) - - local keymaps = { - n = { - ["K"] = { - cmd = ":Lspsaga hover_doc" - }, - ["rn"] = { - cmd = ":Lspsaga rename" - }, - ["gr"] = { - cmd = ":Lspsaga finder" - }, - ["lt"] = { - cmd = ":Lspsaga peek_type_definition" - }, - ["ld"] = { - cmd = ":Lspsaga peek_definition" - }, - ["ca"] = { - cmd = ":Lspsaga code_action" - }, - ["lc"] = { - cmd = ":Lspsaga incoming_calls" - }, - } - } - local utils = require("utils") - utils.add_opts_to_all_mappings(keymaps, { silent = true }) - utils.add_keymaps(keymaps) - end, + opts = { + request_timeout = 750, + symbol_in_winbar = { + enable = false, + }, + implement = { + enable = false, + }, + outline = { + enable = false, + win_width = 52, + }, + ui = { + border = "rounded", + title = false, + }, + code_action = { + extend_gitsigns = true + }, + hover = { + jump_on_first_press = true + }, + }, + keys = { + { "K", ":Lspsaga hover_doc", silent = true, }, + { "rn", ":Lspsaga rename", silent = true, }, + { "gr", ":Lspsaga finder", silent = true, }, + { "lt", ":Lspsaga peek_type_definition", silent = true, }, + { "ld", ":Lspsaga peek_definition", silent = true, }, + { "ca", ":Lspsaga code_action", silent = true, }, + { "lc", ":Lspsaga incoming_calls", silent = true, }, + }, } diff --git a/nvim/lua/plugs/lualine.lua b/nvim/lua/plugs/lualine.lua index d7c19bd..eec34b5 100644 --- a/nvim/lua/plugs/lualine.lua +++ b/nvim/lua/plugs/lualine.lua @@ -1,7 +1,5 @@ -local wm = require("window_management") - local function resize_mode() - if wm.is_in_resizing_mode() then + if require("window_management").is_in_resizing_mode() then return "▲ Resizing ▼" else return "" @@ -15,46 +13,44 @@ return { }, event = "VeryLazy", lazy = true, - config = function() - require("lualine").setup { - options = { - theme = "ayu", - section_separators = { - left = "", - right = "", - }, - component_separators = { - left = "", - right = "" - }, - icons_enabled = true, + opts = { + options = { + theme = "ayu", + section_separators = { + left = "", + right = "", }, - sections = { - lualine_a = { "mode" }, - lualine_b = { - "branch", - { - "diagnostics", - sources = { "nvim_lsp" }, - sections = { "error", "warn", "info", "hint" }, - update_in_insert = false, - }, - resize_mode, + component_separators = { + left = "", + right = "" + }, + icons_enabled = true, + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { + "branch", + { + "diagnostics", + sources = { "nvim_lsp" }, + sections = { "error", "warn", "info", "hint" }, + update_in_insert = false, }, - lualine_c = { "buffers" }, - lualine_x = { "encoding", "fileformat", "filetype" }, - lualine_y = { "progress" }, - lualine_z = { "location" } + resize_mode, }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = {}, - lualine_x = {}, - lualine_y = {}, - lualine_z = {} - }, - tabline = {}, - } - end + lualine_c = { "buffers" }, + lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" } + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {}, + lualine_x = {}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + } } diff --git a/nvim/lua/plugs/neogit.lua b/nvim/lua/plugs/neogit.lua index a655912..e510511 100644 --- a/nvim/lua/plugs/neogit.lua +++ b/nvim/lua/plugs/neogit.lua @@ -14,16 +14,8 @@ return { }, event = "VeryLazy", lazy = true, - config = function() - local neogit = require("neogit") - neogit.setup() - - require("utils").add_keymaps({ - n = { - ["g"] = { - cmd = function() neogit.open({ kind = "vsplit" }) end, - }, - } - }) - end + opts = {}, + keys = { + { "g", function() require("neogit").open({ kind = "vsplit" }) end } + }, } diff --git a/nvim/lua/plugs/nvim-dap.lua b/nvim/lua/plugs/nvim-dap.lua index ea09c95..5756f97 100644 --- a/nvim/lua/plugs/nvim-dap.lua +++ b/nvim/lua/plugs/nvim-dap.lua @@ -5,81 +5,57 @@ local are_stepping_keymaps_active = false return { "mfussenegger/nvim-dap", dependencies = { - "rcarriga/nvim-dap-ui", - + { + "rcarriga/nvim-dap-ui", + opts = { + controls = { + enabled = false, + }, + layouts = { + { + elements = { + { + id = "watches", + size = 0.5 + }, + { + id = "stacks", + size = 0.5 + } + }, + position = "bottom", + size = 15 + } + }, + }, + }, -- Special adapters - "leoluz/nvim-dap-go", - "mfussenegger/nvim-dap-python", + { "leoluz/nvim-dap-go", opts = {} }, + { "mfussenegger/nvim-dap-python", }, - { "nvim-neotest/nvim-nio", lazy = true }, - "LiadOz/nvim-dap-repl-highlights", - "theHamsta/nvim-dap-virtual-text", - "Weissle/persistent-breakpoints.nvim", + { "nvim-neotest/nvim-nio", lazy = true }, + { "LiadOz/nvim-dap-repl-highlights", opts = {} }, + { "theHamsta/nvim-dap-virtual-text", opts = {} }, + { "Weissle/persistent-breakpoints.nvim", opts = { load_breakpoints_event = { "BufReadPost" } } }, }, config = function() local dap = require("dap") - local dapui = require("dapui") - -- Special adapters - require("dap-go").setup() + require("dap-python").setup("python3") - -- Special adapters - require("dap.ext.vscode").load_launchjs() - require("persistent-breakpoints").setup { - load_breakpoints_event = { "BufReadPost" } - } - - require("nvim-dap-repl-highlights").setup() - require("nvim-dap-virtual-text").setup() local virtual_text = require("nvim-dap-virtual-text/virtual_text") local breakpoint_api = require("persistent-breakpoints.api") - dapui.setup({ - controls = { - enabled = false, - }, - layouts = { - { - elements = { - { - id = "watches", - size = 0.5 - }, - { - id = "stacks", - size = 0.5 - } - }, - position = "bottom", - size = 15 - } - }, - }) - local stepping_keymaps = { - n = { - ["m"] = { - cmd = function() - dap.step_out() - end - }, - ["n"] = { - cmd = function() - dap.step_over() - end - }, - ["i"] = { - cmd = function() - dap.step_into() - end - }, - } + { "m", function() dap.step_out() end }, + { "n", function() dap.step_over() end }, + { "i", function() dap.step_into() end }, } local function enter_debug_mode() - dapui.open() + require("dapui").open() if not are_stepping_keymaps_active then - utils.add_temporary_keymaps(stepping_keymaps) + utils.set_keymap_list(stepping_keymaps) are_stepping_keymaps_active = true end @@ -87,9 +63,9 @@ return { end local function exit_debug_mode() - dapui.close() + require("dapui").close() if are_stepping_keymaps_active then - utils.remove_keymaps(stepping_keymaps) + utils.del_keymap_list(stepping_keymaps) are_stepping_keymaps_active = false end @@ -117,36 +93,17 @@ return { exit_debug_mode() end - utils.add_keymaps({ - n = { - ["dr"] = { - cmd = function() - dap.continue() - end - }, - ["bt"] = { - cmd = function() - breakpoint_api.toggle_breakpoint() - end - }, - ["bc"] = { - cmd = function() - breakpoint_api.set_conditional_breakpoint() - end - }, - ["br"] = { -- breakpoint remove - cmd = function() - breakpoint_api.clear_all_breakpoints() - end - }, - ["ds"] = { - cmd = function() - dap.disconnect({ terminateDebuggee = true }) - dap.close() - exit_debug_mode() - end - }, - } + local function dap_stop() + dap.disconnect({ terminateDebuggee = true }) + dap.close() + exit_debug_mode() + end + utils.set_keymap_list({ + { "dr", dap.continue }, + { "bt", breakpoint_api.toggle_breakpoint }, + { "bc", breakpoint_api.set_conditional_breakpoint }, + { "br", breakpoint_api.clear_all_breakpoints }, + { "ds", dap_stop }, }) end, } diff --git a/nvim/lua/plugs/plenary.lua b/nvim/lua/plugs/plenary.lua index 0c63989..6781ca7 100644 --- a/nvim/lua/plugs/plenary.lua +++ b/nvim/lua/plugs/plenary.lua @@ -1,4 +1,5 @@ return { "nvim-lua/plenary.nvim", + branch = "master", lazy = true, } diff --git a/nvim/lua/plugs/rustaceanvim.lua b/nvim/lua/plugs/rustaceanvim.lua index c3de664..9dc473c 100644 --- a/nvim/lua/plugs/rustaceanvim.lua +++ b/nvim/lua/plugs/rustaceanvim.lua @@ -30,29 +30,9 @@ return { }) end - utils.add_keymaps({ - n = { - ["gd"] = { - cmd = function() - vim.lsp.buf.definition() - end, - opts = { - noremap = true, - silent = true, - buffer = bufnr, - } - }, - ["gD"] = { - cmd = function() - vim.lsp.buf.declaration() - end, - opts = { - noremap = true, - silent = true, - buffer = bufnr, - } - }, - } + utils.set_keymap_list({ + { "gd", function() vim.lsp.buf.definition({ reuse_win = true, }) end, { noremap = true, buffer = bufnr } }, + { "gD", function() vim.lsp.buf.declaration({ reuse_win = true, }) end, { noremap = true, buffer = bufnr } }, }) end, } diff --git a/nvim/lua/terminal.lua b/nvim/lua/terminal.lua index fd522f9..36ee757 100644 --- a/nvim/lua/terminal.lua +++ b/nvim/lua/terminal.lua @@ -1,10 +1,8 @@ -local utils = require("utils") -local wm = require("window_management") - local terminal_window = nil local terminal_bufnr = nil local function open_terminal_window() + local utils = require("utils") if terminal_bufnr and vim.api.nvim_buf_is_valid(terminal_bufnr) and utils.is_buf_buftype(terminal_bufnr, "terminal") then vim.cmd("botright split") terminal_window = vim.api.nvim_get_current_win() @@ -23,6 +21,7 @@ local function toggle_terminal() return end + local utils = require("utils") open_terminal_window() local term_height = vim.api.nvim_get_option("lines") @@ -37,13 +36,7 @@ local function toggle_terminal() vim.api.nvim_command("startinsert") end -utils.add_keymaps({ - n = { - ["h"] = { - cmd = function() - toggle_terminal() - wm.autosize_windows() - end, - } - } -}) +vim.keymap.set("n", "h", function() + toggle_terminal() + require("window_management").autosize_windows() +end) diff --git a/nvim/lua/utils.lua b/nvim/lua/utils.lua index ff806ba..d250a7b 100644 --- a/nvim/lua/utils.lua +++ b/nvim/lua/utils.lua @@ -1,10 +1,17 @@ local M = {} -local overridden_default_keymaps = {} +function M.set_keymap_list(keymap_list, mode) + mode = mode or "n" + M.foreach(keymap_list, function(mapping) + vim.keymap.set(mode, mapping[1], mapping[2], mapping[3] or {}) + end) +end -local function is_single_keymap_table(map_table) - assert(map_table) - return map_table.n or map_table.t or map_table.i or map_table.v or map_table.x or map_table.o +function M.del_keymap_list(keymap_list, mode) + mode = mode or "n" + M.foreach(keymap_list, function(mapping) + vim.keymap.del(mode, mapping[1]) + end) end function M.get_file_names_in_dir(dir, expr, strip_extension) @@ -75,94 +82,6 @@ function M.add_opts_to_all_mappings(mappings, opts) end end -local function pass_keymap_tbl_to_fn(maps, fn) - if is_single_keymap_table(maps) then - fn(maps) - else - for _, map_table in pairs(maps) do - fn(map_table) - end - end -end - -local function get_keymaps(mode, buffer) - if buffer then - return vim.api.nvim_buf_get_keymap(buffer, mode) - end - - return vim.api.nvim_get_keymap(mode) -end - -function M.add_temporary_keymaps(maps) - assert(maps) - - pass_keymap_tbl_to_fn(maps, function(map_table) - for mode, entries in pairs(map_table) do - -- We make an assumptino here which is that all the entries are buffers, or not buffers. - -- Meaning, we only check the first entry and trust that the rest are the same. - local result = get_keymaps(mode, (function() - for _, entry in pairs(entries) do - -- nil buffer is treated as a global keymap - return entry.buffer - end - end)()) - - for code, _ in pairs(entries) do - for _, map in ipairs(result) do - if map.lhs == code then - if not overridden_default_keymaps[mode] then - overridden_default_keymaps[mode] = {} - end - - overridden_default_keymaps[mode][code] = { - cmd = map.callback or map.rhs, - opts = { - noremap = map.noremap == 1, - expr = map.expr == 1, - silent = map.silent == 1, - nowait = map.nowait == 1, - script = map.script == 1, - buffer = type(map.buffer) == "number" and map.buffer or nil, - }, - } - end - end - end - end - end) - - M.add_keymaps(maps) -end - -function M.add_keymaps(maps) - assert(maps) - - pass_keymap_tbl_to_fn(maps, function(map_table) - for mode, entries in pairs(map_table) do - for code, info in pairs(entries) do - vim.keymap.set(mode, code, info.cmd, info.opts) - end - end - end) -end - -function M.remove_keymaps(maps) - assert(maps) - - pass_keymap_tbl_to_fn(maps, function(map_table) - for mode, entries in pairs(map_table) do - local overriden_mode = overridden_default_keymaps[mode] - for code, _ in pairs(entries) do - vim.keymap.del(mode, code) - - if overriden_mode and overriden_mode[code] then - vim.keymap.set(mode, code, overriden_mode[code].cmd, overriden_mode[code].opts) - end - end - end - end) -end - function M.is_buf_filetype(bufnr, filetype) return vim.api.nvim_buf_get_option(bufnr, "filetype") == filetype end diff --git a/nvim/lua/window_management.lua b/nvim/lua/window_management.lua index 5df5400..6adfbf3 100644 --- a/nvim/lua/window_management.lua +++ b/nvim/lua/window_management.lua @@ -189,75 +189,35 @@ end function M.setup() local resizing_mode_keymaps = { - n = { - [""] = { - cmd = function() resize_window(vim.api.nvim_get_current_win(), "h") end - }, - [""] = { - cmd = function() resize_window(vim.api.nvim_get_current_win(), "j") end - }, - [""] = { - cmd = function() resize_window(vim.api.nvim_get_current_win(), "k") end - }, - [""] = { - cmd = function() resize_window(vim.api.nvim_get_current_win(), "l") end - }, - [""] = { - cmd = function() exit_resizing_mode() end - }, - [""] = { - cmd = function() exit_resizing_mode() end - }, - ["="] = { - cmd = function() M.autosize_windows() end - }, - } + { "", function() resize_window(vim.api.nvim_get_current_win(), "h") end }, + { "", function() resize_window(vim.api.nvim_get_current_win(), "j") end }, + { "", function() resize_window(vim.api.nvim_get_current_win(), "k") end }, + { "", function() resize_window(vim.api.nvim_get_current_win(), "l") end }, + { "", function() exit_resizing_mode() end }, + { "", function() exit_resizing_mode() end }, + { "=", function() M.autosize_windows() end }, } local enter_resizing_mode_keymaps = { - n = { - [""] = { - cmd = function() enter_resizing_mode() end - } - }, + { "", function() enter_resizing_mode() end } } local window_shifting_keymaps = { - n = { - [""] = { - cmd = function() - swap_window("h") - end - }, - [""] = { - cmd = function() - swap_window("j") - end - }, - [""] = { - cmd = function() - swap_window("k") - end - }, - [""] = { - cmd = function() - swap_window("l") - end - }, - }, + { "", function() swap_window("h") end }, + { "", function() swap_window("j") end }, + { "", function() swap_window("k") end }, + { "", function() swap_window("l") end }, } - utils.add_keymaps({ - window_shifting_keymaps, - enter_resizing_mode_keymaps - }) + utils.set_keymap_list(window_shifting_keymaps) + utils.set_keymap_list(enter_resizing_mode_keymaps) local function on_resize_mode_enter() - utils.remove_keymaps(enter_resizing_mode_keymaps) - utils.add_keymaps(resizing_mode_keymaps) + M.del_keymap_list(enter_resizing_mode_keymaps) + M.set_keymap_list(resizing_mode_keymaps) end local function on_resize_mode_exit() - utils.remove_keymaps(resizing_mode_keymaps) - utils.add_keymaps(enter_resizing_mode_keymaps) + M.del_keymap_list(resizing_mode_keymaps) + M.set_keymap_list(enter_resizing_mode_keymaps) end local window_management_augroup = "WindowManagementEvents"