From 49f6a0ef5854c72a2d6bf10507f0bc6e22ed80e5 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 12 Dec 2023 23:24:16 +0100 Subject: [PATCH] nvim: Refactor plugin mappings to loading code --- nvim/.config/nvim/lazy-lock.json | 1 - nvim/.config/nvim/lua/core/lazy.lua | 6 +- nvim/.config/nvim/lua/core/mappings.lua | 148 +----------------- nvim/.config/nvim/lua/plugins/core.lua | 53 +++++++ nvim/.config/nvim/lua/plugins/editing.lua | 14 +- .../.config/nvim/lua/plugins/filebrowsers.lua | 9 ++ nvim/.config/nvim/lua/plugins/ide.lua | 13 +- nvim/.config/nvim/lua/plugins/prose.lua | 93 +++++++++-- nvim/.config/nvim/lua/plugins/telescope.lua | 113 ++++++++++--- 9 files changed, 273 insertions(+), 177 deletions(-) diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index 2110ae4..227dd1b 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -23,7 +23,6 @@ "cmp-tmux": { "branch": "main", "commit": "97ec06b8030b8bf6d1fd83d49bdd16c98e04c845" }, "cmp-treesitter": { "branch": "master", "commit": "13e4ef8f4dd5639fca2eb9150e68f47639a9b37d" }, "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, - "codeium.nvim": { "branch": "main", "commit": "a0d43300f9a17a6ac775947ae4fb6b99ac5a92d0" }, "completion-vcard": { "branch": "master", "commit": "2220fd517a985ececed1adcf0e5be8f2815564c7" }, "conform.nvim": { "branch": "master", "commit": "ce95e6b2a072d81fd312ff213f241cacab1eccef" }, "dial.nvim": { "branch": "master", "commit": "54b503f906bc9e5ab85288414840a1b86d40769f" }, diff --git a/nvim/.config/nvim/lua/core/lazy.lua b/nvim/.config/nvim/lua/core/lazy.lua index 840f4e2..6c2c0d3 100644 --- a/nvim/.config/nvim/lua/core/lazy.lua +++ b/nvim/.config/nvim/lua/core/lazy.lua @@ -34,5 +34,9 @@ vim.opt.rtp:prepend(lazypath) require("lazy").setup({ spec = { { import = "plugins" } }, defaults = { lazy = true, version = "*" }, - performance = { rtp = { disabled_plugins = { "netrw", "netrwPlugin" } } }, + performance = { + rtp = { disabled_plugins = { "netrw", "netrwPlugin" } }, + cache = { enable = false }, + }, }) +vim.keymap.set("n", "vl", ":Lazy", { desc = "Lazy" }) diff --git a/nvim/.config/nvim/lua/core/mappings.lua b/nvim/.config/nvim/lua/core/mappings.lua index 3b3d39b..d6e2442 100644 --- a/nvim/.config/nvim/lua/core/mappings.lua +++ b/nvim/.config/nvim/lua/core/mappings.lua @@ -1,7 +1,14 @@ local map = vim.keymap.set -local prefix = require("which-key").register local is_available = require("util").is_available +if is_available("which-key") then + local prefix = require("which-key").register + prefix({ ["v"] = { name = "+vim" } }) + prefix({ ["s"] = { name = "+show" } }) + prefix({ ["s"] = { name = "+set" } }) + prefix({ ["Z"] = { name = "+spelling" } }) +end + -- The general ideas behind these mappings: -- -- * Leader prefix is the generally preferred way to map new things, however @@ -112,66 +119,6 @@ map("n", "T", ":tabedit | Vifm", { desc = "open tab" }) -- select the whole buffer with -a map("n", "a", "ggVG", { desc = "select all" }) --- PLUGIN: Navigator.nvim -map("n", "h", 'lua require("Navigator").left()', { silent = true }) -map("n", "k", 'lua require("Navigator").up()', { silent = true }) -map("n", "l", 'lua require("Navigator").right()', { silent = true }) -map("n", "j", 'lua require("Navigator").down()', { silent = true }) -map("n", "p", 'lua require("Navigator").previous()', { silent = true }) - --- PLUGIN: Vifm.vim --- open/close file tree with leader-e -map("n", "e", ":Vifm", { desc = "browse files" }) --- open current file tree with current file directory -map("n", "E", ":Vifm getcwd()", { desc = "browse project" }) - --- set 'v'im-related options -prefix({ ["v"] = { name = "+vim" } }) -map("n", "vc", ":Vifm " .. vim.fn.stdpath("config") .. "/lua", { desc = "open config" }) -map("n", "vh", ":lua require 'telescope.builtin'.help_tags()", { desc = "help tags" }) -map("n", "vH", ":lua require 'telescope.builtin'.man_pages()", { desc = "man pages" }) -map( - "n", - "vC", - ":lua require 'telescope.builtin'.colorscheme(require 'telescope.themes'.get_ivy())", - { desc = "colorschemes" } -) -map("n", "vl", ":Lazy", { desc = "Lazy" }) - --- PLUGIN: Telescope GLOBAL FUZZY FINDING --- buffers and files in current workdir -prefix({ ["f"] = { name = "+find" } }) -map( - "n", - "fb", - ":lua require 'telescope.builtin'.buffers(require 'telescope.themes'.get_ivy())", - { desc = "list buffers" } -) --- most recently used / MRU, bound to S since it is essentially a larger --- go-back intention than just buffers -map( - "n", - "fo", - ":lua require 'telescope.builtin'.oldfiles(require 'telescope.themes'.get_ivy())", - { desc = "list old files" } -) --- fuzzy find files in cwd -map("n", "ff", ":lua require 'telescope.builtin'.find_files()", { desc = "find files" }) --- fuzzy find hidden files in cwd -map("n", "fh", ":lua require 'telescope.builtin'.find_files({hidden=true})", { desc = "find hidden files" }) --- general full-text search in cwd with rg -map("n", "fw", ":lua require 'telescope.builtin'.live_grep()", { desc = "grep search" }) - --- git status -map("n", "fg", ":lua require 'telescope.builtin'.git_status()", { desc = "git status" }) --- git buffercommits -map("n", "fc", ":lua require 'telescope.builtin'.git_bcommits()", { desc = "git buffer commits" }) --- git commitlog -map("n", "fl", ":lua require 'telescope.builtin'.git_commits()", { desc = "git commit log" }) - --- spell suggestions -map("n", "z=", ":lua require 'telescope.builtin'.spell_suggest(require 'telescope.themes'.get_ivy())") - -- Format current Paragraph (esp useful in prose writing) map("n", "q", "gqap", { silent = true, desc = "Format current paragraph" }) map("x", "q", "gq", { silent = true, desc = "Format {motion}" }) @@ -180,7 +127,6 @@ map("n", "Q", "vapJgqap", { silent = true, desc = "Unformat then fo -- SPELL CHECKING -- Move to the prev/next spelling error with [S ]S -- Move to the prev/next spelling error or suggestion with [s ]s -prefix({ ["Z"] = { name = "+Spelling" } }) map("n", "ZZ", ":setlocal spell! spelllang=en_us,en_gb,de_de", { desc = "Toggle spellcheck" }) map("n", "ZE", ":setlocal spell! spelllang=en_us", { desc = "Toggle EN_US spellcheck" }) map("n", "ZB", ":setlocal spell! spelllang=en_gb", { desc = "Toggle EN_GB spellcheck" }) @@ -188,81 +134,3 @@ map("n", "ZD", ":setlocal spell! spelllang=de_de", { desc = "To -- undo last spelling mistake from insert and normal mode map("i", "", "u[s1z=`]au") map("n", "z", "ms[s1z=`s", { desc = "Fix last spell error" }) - -prefix({ ["s"] = { name = "+show" } }) --- Set vim to distraction free prose mode -map("n", "sz", ":ZenMode", { silent = true }) --- PLUGIN: mini.nvim -map("n", "sm", ":lua MiniMap.toggle()", { silent = true, desc = "minimap" }) -map("n", "ss", ":lua MiniStarter.open()", { desc = "startpage" }) - --- PLUGIN: symbols-outline.nvim -map("n", "so", "AerialNavToggle", { silent = true, desc = "symbol navigator" }) -map("n", "sO", "AerialToggle", { silent = true, desc = "symbol outline" }) - --- PLUGIN: nvim-tree -map("n", "se", "NvimTreeToggle", { silent = true, desc = "filetree" }) - --- PLUGIN: nvim-tree -map("n", "sd", "Trouble workspace_diagnostics", { silent = true, desc = "diagnostics workspace" }) -map("n", "sD", "Trouble document_diagnostics", { silent = true, desc = "diagnostics document" }) - --- PLUGIN: easy-align --- Start interactive EasyAlign in visual mode (e.g. vipga) -map("x", "ga", "(EasyAlign)") --- Start interactive EasyAlign for a motion/text object (e.g. gaip) -map("n", "ga", "(EasyAlign)") - --- trim trailing whitespaces with mini.nvim trailspace -map("n", "w", function() - require("mini.trailspace").trim() -end, { noremap = true }) - --- PLUGIN: dial-increment -map("n", "", "(dial-increment)") -map("n", "", "(dial-decrement)") -map("v", "", "(dial-increment)") -map("v", "", "(dial-increment)") -map("v", "g", "g(dial-increment)") -map("v", "g", "g(dial-increment)") - --- PLUGIN: zettelkasten.nvim -map("n", "", [[:silent lua require 'zettelkasten'.link_follow()]]) -map("v", "", [[:lua require 'zettelkasten'.link_follow(true)]]) -prefix({ ["n"] = { name = "+notes" } }) -map("n", "ni", [[:lua require 'zettelkasten'.index_open() ]], { desc = "index page" }) --- PLUGIN: zk -map("n", "nn", "ZkNotes { sort = { 'modified' } }", { desc = "note list" }) -map( - "n", - "nf", - "ZkNotes { sort = { 'modified' }, match = { vim.fn.input('Search: ') } }", - { desc = "note search" } -) -map("n", "nt", "ZkTags", { desc = "note tags" }) -map("n", "nc", "ZkCd", { desc = "notes directory" }) -prefix({ ["n"] = { name = "+note" } }) -map("n", "nl", "ZkLinks", { desc = "note links" }) -map("n", "nb", "ZkLinks", { desc = "note backlinks" }) -map("n", "nn", "ZkNew { title = vim.fn.input('Title: ') }", { desc = "new note" }) -prefix({ ["n"] = { name = "+note", mode = "v" } }) -map("v", "nn", ":ZkNewFromTitleSelection", { desc = "title from selection" }) -map("v", "nN", ":ZkNewFromContentSelection", { desc = "content from selection" }) -map("v", "nf", ":ZkMatch", { desc = "find note from selection" }) - --- PLUGIN: toggleterm.nvim --- create a lazygit or python window, set up in toggleterm settings --- TODO create ability to go into python environment when in poetry venv and/or euporie/jupyter notebook -map("n", "sg", ":Lazygit") -map("n", "sG", ":Lazygit!") -map("n", "sp", ":Pythonterm") -map("n", "sP", ":Pythonterm!") - -prefix({ ["s"] = { name = "+set" } }) --- PLUGIN: wrapping.nvim -map( - "n", - "sw", - [[:lua require('wrapping').toggle_wrap_mode() ]], - { silent = true, desc = "toggle wrap mode" } -) diff --git a/nvim/.config/nvim/lua/plugins/core.lua b/nvim/.config/nvim/lua/plugins/core.lua index 7162fd1..8bfcc71 100644 --- a/nvim/.config/nvim/lua/plugins/core.lua +++ b/nvim/.config/nvim/lua/plugins/core.lua @@ -5,6 +5,43 @@ return { branch = "master", config = true, event = "VeryLazy", + keys = { + { + "h", + function() + require("Navigator").left() + end, + { silent = true }, + }, + { + "k", + function() + require("Navigator").up() + end, + { silent = true }, + }, + { + "l", + function() + require("Navigator").right() + end, + { silent = true }, + }, + { + "j", + function() + require("Navigator").down() + end, + { silent = true }, + }, + { + "p", + function() + require("Navigator").previous() + end, + { silent = true }, + }, + }, }, -- jump between letters with improved fFtT quicksearch, mimics sneak { "ggandor/lightspeed.nvim", event = "BufEnter" }, @@ -24,6 +61,16 @@ return { require("plugins.config.mini") end, event = "VimEnter", -- need to load pretty soon for Starter screen + keys = { + { "sm", ":lua MiniMap.toggle()", { silent = true, desc = "minimap" } }, + { "ss", ":lua MiniStarter.open()", { desc = "startpage" } }, + { + "w", + function() + require("mini.trailspace").trim() + end, + }, + }, }, -- simpler, programmable and multiple terminal toggling for nvim { @@ -32,6 +79,12 @@ return { require("plugins.config.toggleterm") end, cmd = { "ToggleTerm", "TermExec", "Lazygit", "Pythonterm" }, + keys = { + { "sg", ":Lazygit" }, + { "sG", ":Lazygit!" }, + { "sp", ":Pythonterm" }, + { "sP", ":Pythonterm!" }, + }, }, -- colorschemes { diff --git a/nvim/.config/nvim/lua/plugins/editing.lua b/nvim/.config/nvim/lua/plugins/editing.lua index 4730382..70d59dc 100644 --- a/nvim/.config/nvim/lua/plugins/editing.lua +++ b/nvim/.config/nvim/lua/plugins/editing.lua @@ -7,7 +7,11 @@ return { -- Align tables and other alignable things { "junegunn/vim-easy-align", - event = "VeryLazy", + event = "InsertEnter", + keys = { + { "ga", "(EasyAlign)", mode = "n" }, + { "ga", "(EasyAlign)", mode = "x" }, + }, }, -- surround things with other things using ys/cs/ds { "kylechui/nvim-surround", version = "*", config = true, event = "VeryLazy" }, @@ -48,5 +52,13 @@ return { }) end, event = "InsertEnter", + keys = { + { "", "(dial-increment)", mode = "n" }, + { "", "(dial-decrement)", mode = "n" }, + { "", "(dial-increment)", mode = "v" }, + { "", "(dial-increment)", mode = "v" }, + { "g", "g(dial-increment)", mode = "v" }, + { "g", "g(dial-increment)", mode = "v" }, + }, }, } diff --git a/nvim/.config/nvim/lua/plugins/filebrowsers.lua b/nvim/.config/nvim/lua/plugins/filebrowsers.lua index 476f17d..411f81b 100644 --- a/nvim/.config/nvim/lua/plugins/filebrowsers.lua +++ b/nvim/.config/nvim/lua/plugins/filebrowsers.lua @@ -8,11 +8,20 @@ return { vim.g.vifm_exec_args = '-c "set vifminfo=" -c "set statusline=" -c "only"' end, cmd = "Vifm", + keys = { + { "e", "Vifm", desc = "browse files" }, + { "E", ":Vifm getcwd()", desc = "browse project" }, + { "vc", ":Vifm " .. vim.fn.stdpath("config") .. "/lua", desc = "open config" }, + }, + event = { "BufEnter" }, }, -- integrate file manager { "nvim-tree/nvim-tree.lua", -- integrate file tree config = true, dependencies = { "nvim-tree/nvim-web-devicons", config = true }, cmd = "NvimTreeToggle", + keys = { + { "se", "NvimTreeToggle", desc = "filetree", silent = true }, + }, }, } diff --git a/nvim/.config/nvim/lua/plugins/ide.lua b/nvim/.config/nvim/lua/plugins/ide.lua index 7c3730c..9ec6d5f 100644 --- a/nvim/.config/nvim/lua/plugins/ide.lua +++ b/nvim/.config/nvim/lua/plugins/ide.lua @@ -25,6 +25,10 @@ return { opts = { backends = { "treesitter", "lsp", "markdown", "man" }, }, + keys = { + { "so", "AerialNavToggle", silent = true, desc = "symbol navigator" }, + { "sO", "AerialToggle", silent = true, desc = "symbol outline" }, + }, }, -- lsp setup @@ -247,6 +251,10 @@ return { "TroubleToggle", "TroubleClose", }, + keys = { + { "sd", "Trouble workspace_diagnostics", silent = true, desc = "diagnostics workspace" }, + { "sD", "Trouble document_diagnostics", silent = true, desc = "diagnostics document" }, + }, }, -- testing setup @@ -268,9 +276,8 @@ return { }), }, }) - local status, wk = pcall(require, "which-key") - if status then - wk.register({ ["t"] = { name = "+test" } }) + if require("util").is_available("which-key") then + require("which-key").register({ ["t"] = { name = "+test" } }) end end, ft = { "python" }, diff --git a/nvim/.config/nvim/lua/plugins/prose.lua b/nvim/.config/nvim/lua/plugins/prose.lua index 5dbb327..4f3e4fb 100644 --- a/nvim/.config/nvim/lua/plugins/prose.lua +++ b/nvim/.config/nvim/lua/plugins/prose.lua @@ -3,17 +3,42 @@ local writing_ft = { "quarto", "pandoc", "markdown", "text", "tex" } local prose_plugs = { -- UI improvements -- provide distraction free writing - { "folke/zen-mode.nvim", config = true, cmd = { "ZenMode" }, dependencies = { "folke/twilight.nvim" } }, + { + "folke/zen-mode.nvim", + config = true, + cmd = { "ZenMode" }, + dependencies = { "folke/twilight.nvim" }, + keys = { { "sz", ":ZenMode", { silent = true } } }, + }, { "andrewferrier/wrapping.nvim", - config = function() - require("wrapping").setup({ - create_keymappings = false, - notify_on_switch = false, - softener = { markdown = true, text = true, asciidoc = true }, - }) - end, - lazy = false, + opts = { + create_keymappings = false, + notify_on_switch = false, + softener = { quarto = true, markdown = true, text = true, asciidoc = true }, + auto_set_mode_filetype_allowlist = { + "asciidoc", + "gitcommit", + "latex", + "mail", + "markdown", + "rst", + "tex", + "text", + "quarto", + }, + }, + event = { "BufReadPre", "BufNewFile" }, + keys = { + { + "sw", + function() + require("wrapping").toggle_wrap_mode() + end, + silent = true, + desc = "toggle wrap mode", + }, + }, }, -- displays prettier headlines mimicking the ones in emacs orgmode { @@ -35,6 +60,12 @@ local prose_plugs = { { "mickael-menu/zk-nvim", config = function() + if require("util").is_available("which-key") then + local prefix = require("which-key").register + prefix({ ["n"] = { name = "+notes" } }) + prefix({ ["n"] = { name = "+note" } }) + prefix({ ["n"] = { name = "+note", mode = "v" } }) + end require("zk").setup({ picker = "telescope" }) end, ft = writing_ft, @@ -52,9 +83,51 @@ local prose_plugs = { "ZkNotes", "ZkTags", }, + keys = { + { "nn", "ZkNotes { sort = { 'modified' } }", desc = "note list" }, + { + "nf", + "ZkNotes { sort = { 'modified' }, match = { vim.fn.input('Search: ') } }", + desc = "note search", + }, + { "nt", "ZkTags", desc = "note tags" }, + { "nc", "ZkCd", desc = "notes directory" }, + { "nl", "ZkLinks", desc = "note links" }, + { "nb", "ZkLinks", desc = "note backlinks" }, + { "nn", "ZkNew { title = vim.fn.input('Title: ') }", desc = "new note" }, + { "nn", ":ZkNewFromTitleSelection", desc = "title from selection", mode = "v" }, + { "nN", ":ZkNewFromContentSelection", desc = "content from selection", mode = "v" }, + { "nf", ":ZkMatch", desc = "find note from selection", mode = "v" }, + }, }, -- simple static markdown linking and link following using zettel IDs - { "marty-oehme/zettelkasten.nvim", ft = writing_ft, event = "VeryLazy" }, + { + "marty-oehme/zettelkasten.nvim", + ft = writing_ft, + keys = { + { + "", + function() + require("zettelkasten").link_follow() + end, + silent = true, + }, + { + "", + function() + require("zettelkasten").link_follow(true) + end, + mode = "v", + }, + { + "ni", + function() + require("zettelkasten").index_open() + end, + desc = "index page", + }, + }, + }, -- syntax highlighting for markdown criticmarkup (comments, additions, ...) { "vim-pandoc/vim-criticmarkup", ft = writing_ft }, diff --git a/nvim/.config/nvim/lua/plugins/telescope.lua b/nvim/.config/nvim/lua/plugins/telescope.lua index 408f89e..91e3e97 100644 --- a/nvim/.config/nvim/lua/plugins/telescope.lua +++ b/nvim/.config/nvim/lua/plugins/telescope.lua @@ -7,9 +7,11 @@ return { "nvim-lua/plenary.nvim", { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, }, - event = "VeryLazy", cmd = "Telescope", config = function() + if require("util").is_available("which-key") then + require("which-key").register({ ["f"] = { name = "+find" } }) + end -- Setup up telescope fuzzy finding settings -- -- Makes use of optionally installed external programs to work fully: @@ -44,26 +46,8 @@ return { borderchars = { { "─", "│", "─", "│", "┌", "┐", "┘", "└" }, prompt = { "─", "│", " ", "│", "┌", "┐", "│", "│" }, - results = { - "─", - "│", - "─", - "│", - "├", - "┤", - "┘", - "└", - }, - preview = { - "─", - "│", - "─", - "│", - "┌", - "┐", - "┘", - "└", - }, + results = { "─", "│", "─", "│", "├", "┤", "┘", "└" }, + preview = { "─", "│", "─", "│", "┌", "┐", "┘", "└" }, }, width = 0.8, previewer = false, @@ -73,5 +57,92 @@ return { }) require("telescope").load_extension("fzf") end, + keys = { + { + "vh", + function() + require("telescope.builtin").help_tags() + end, + desc = "help tags", + }, + { + "vH", + function() + require("telescope.builtin").man_pages() + end, + desc = "man pages", + }, + { + "vC", + function() + require("telescope.builtin").colorscheme(require("telescope.themes").get_ivy()) + end, + desc = "colorschemes" , + }, + + { + "fb", + function() + require("telescope.builtin").buffers(require("telescope.themes").get_ivy()) + end, + desc = "list buffers", + }, + { + "fo", + function() + require("telescope.builtin").oldfiles(require("telescope.themes").get_ivy()) + end, + desc = "list old files", + }, + { + "ff", + function() + require("telescope.builtin").find_files() + end, + desc = "find files", + }, + { + "fh", + function() + require("telescope.builtin").find_files({ hidden = true }) + end, + desc = "find hidden files", + }, + { + "fw", + function() + require("telescope.builtin").live_grep() + end, + desc = "grep search", + }, + { + "fg", + function() + require("telescope.builtin").git_status() + end, + desc = "git status", + }, + { + "fc", + function() + require("telescope.builtin").git_bcommits() + end, + desc = "git buffer commits", + }, + { + "fl", + function() + require("telescope.builtin").git_commits() + end, + desc = "git commit log", + }, + { + "z=", + function() + require("telescope.builtin").spell_suggest(require("telescope.themes").get_ivy()) + end, + desc = "spell suggest", + }, + }, }, }