From b69548fa38f0616c43281eea01556dcecba02c06 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 6 Jun 2024 20:45:53 +0200 Subject: [PATCH 1/7] nvim: Load nvim-surround as VeryLazy This fixes the somewhat confusing issue of trying to use any of the surround operations before entering insert mode at least once in a file (so, probably as the first operation). Before, the plugin would just silently fail. Now it simply loads very lazily, which does not affect load times strongly. --- nvim/.config/nvim/lua/plugins/editing.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvim/.config/nvim/lua/plugins/editing.lua b/nvim/.config/nvim/lua/plugins/editing.lua index 6c41211..3d9fbda 100644 --- a/nvim/.config/nvim/lua/plugins/editing.lua +++ b/nvim/.config/nvim/lua/plugins/editing.lua @@ -9,7 +9,7 @@ return { }, }, -- surround things with other things using ys/cs/ds - { "kylechui/nvim-surround", config = true, event = "InsertEnter" }, + { "kylechui/nvim-surround", config = true, event = "VeryLazy" }, -- extend the ^a / ^x possibilities to dates, hex, alphabets, markdown headers { From 1771a6133463c2a3cc7c201e619a4ca751f63aca Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 6 Jun 2024 20:50:37 +0200 Subject: [PATCH 2/7] nvim: Use peek for markdown preview where possible On machines that have deno installed, we use peek instead of markdown-preview for html-based previews of md files. The preview is more responsive and in a neater package, as well as just not relying on any vim plugin stuff to the same degree. We still fall back to the old markdown-preview if no deno executable is available. We also change the key maps slightly to prepare for future 'prose' or 'preview' based mappings: All mappings are registered under the `p` layer, with md preview being `pp` and various mindmap operations moved to `pm`. --- nvim/.config/nvim/after/ftplugin/markdown.lua | 23 +++++++++++++++---- nvim/.config/nvim/lua/plugins/prose.lua | 15 +++++++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/nvim/.config/nvim/after/ftplugin/markdown.lua b/nvim/.config/nvim/after/ftplugin/markdown.lua index 19696ba..7f2c06f 100644 --- a/nvim/.config/nvim/after/ftplugin/markdown.lua +++ b/nvim/.config/nvim/after/ftplugin/markdown.lua @@ -5,7 +5,7 @@ if require("core.util").is_available("which-key") then require("which-key").register({ ["e"] = { name = "+criticmarkup" } }) end -if require("zk.util").notebook_root(vim.fn.expand("%:p")) ~= nil then +if require("core.util").is_available("zk") and require("zk.util").notebook_root(vim.fn.expand("%:p")) ~= nil then map("n", "", "lua vim.lsp.buf.definition()", { silent = true }) end @@ -22,11 +22,26 @@ map("n", "[c", "?^```n}:nohl", { desc = "previous code cell" }) map("n", "co", "o```python```k", { desc = "Insert quarto cell below" }) map("n", "cO", "O```python```k", { desc = "Insert quarto cell above" }) +if require("core.util").is_available("which-key") then + require("which-key").register({ ["p"] = { name = "+prose" } }) +end -- show nice md preview in browser (auto-syncs scrolling) -map("n", "cp", "MarkdownPreviewToggle", { desc = "show md preview" }) +if require("core.util").is_available("peek") then + local peek = require("peek") + local function togglePeek() + if peek.is_open() then + peek.close() + else + peek.open() + end + end + map("n", "pp", togglePeek, { desc = "show md preview" }) +else + map("n", "pp", "MarkdownPreviewToggle", { desc = "show md preview" }) +end -- create mindmaps directly from markdown! requires external executable if vim.fn.executable("markmap") then - map("n", "cm", "MarkmapOpen", { desc = "open md mindmap" }) - map("n", "cM", "MarkmapWatch", { desc = "watch for md mindmap" }) + map("n", "pm", "MarkmapOpen", { desc = "open md mindmap" }) + map("n", "pM", "MarkmapWatch", { desc = "watch for md mindmap" }) end diff --git a/nvim/.config/nvim/lua/plugins/prose.lua b/nvim/.config/nvim/lua/plugins/prose.lua index 29b60c6..7caadba 100644 --- a/nvim/.config/nvim/lua/plugins/prose.lua +++ b/nvim/.config/nvim/lua/plugins/prose.lua @@ -8,7 +8,7 @@ local prose_plugs = { config = true, cmd = { "ZenMode" }, dependencies = { "folke/twilight.nvim" }, - keys = { { "sz", ":ZenMode", { silent = true } } }, + keys = { { "sz", ":ZenMode", silent = true, desc = "toggle zen mode" } }, }, { "andrewferrier/wrapping.nvim", @@ -48,8 +48,21 @@ local prose_plugs = { ft = writing_ft, }, -- generate an auto-updating html preview for md files + -- uses the very nice peek if deno is available, otherwise falls back to markdown-preview + { + "toppair/peek.nvim", + event = { "VeryLazy" }, + cond = vim.fn.executable("deno") == 1, + build = "deno task --quiet build:fast", + config = function() + require("peek").setup() + vim.api.nvim_create_user_command("PeekOpen", require("peek").open, {}) + vim.api.nvim_create_user_command("PeekClose", require("peek").close, {}) + end, + }, { "iamcco/markdown-preview.nvim", + cond = vim.fn.executable("deno") == 0, build = function() vim.fn["mkdp#util#install"]() end, From 94c2d83c8695cb1440d9682c3edb6feca0f5c02c Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 6 Jun 2024 22:32:27 +0200 Subject: [PATCH 3/7] nvim: Fix trouble for major version update Fixed for new invocation usage and removed deprecated commands. Added telescope functionality (to push results into trouble) though I am not quite happy with the close coupling yet. Have not found an easy way to only have this mapping be created if trouble exists. --- nvim/.config/nvim/lua/plugins/ide.lua | 7 ++----- nvim/.config/nvim/lua/plugins/telescope.lua | 5 +++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/ide.lua b/nvim/.config/nvim/lua/plugins/ide.lua index c13ff31..21dec00 100644 --- a/nvim/.config/nvim/lua/plugins/ide.lua +++ b/nvim/.config/nvim/lua/plugins/ide.lua @@ -235,13 +235,10 @@ return { opts = {}, cmd = { "Trouble", - "TroubleRefresh", - "TroubleToggle", - "TroubleClose", }, keys = { - { "sd", "Trouble workspace_diagnostics", silent = true, desc = "diagnostics workspace" }, - { "sD", "Trouble document_diagnostics", silent = true, desc = "diagnostics document" }, + { "sd", "Trouble diagnostics toggle", silent = true, desc = "diagnostics workspace" }, + { "sD", "Trouble diagnostics toggle filter.buf=0", silent = true, desc = "diagnostics document" }, }, }, diff --git a/nvim/.config/nvim/lua/plugins/telescope.lua b/nvim/.config/nvim/lua/plugins/telescope.lua index 08fa63c..a32bf82 100644 --- a/nvim/.config/nvim/lua/plugins/telescope.lua +++ b/nvim/.config/nvim/lua/plugins/telescope.lua @@ -36,6 +36,11 @@ return { prompt_prefix = "󰍉 ", selection_caret = "󰳟 ", color_devicons = true, + mappings = { + -- FIXME Find way to only invoke this *IF* trouble plugin is found + i = { [""] = require("trouble.sources.telescope").open }, + n = { [""] = require("trouble.sources.telescope").open }, + } }, pickers = { buffers = { theme = "ivy" }, From 5c4afcb0b32d00647a2736f8fe80ca493451f7a0 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 6 Jun 2024 22:36:16 +0200 Subject: [PATCH 4/7] nvim: Update plugins --- nvim/.config/nvim/lazy-lock.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index 3b080d2..38cfcf4 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -35,10 +35,9 @@ "glance.nvim": { "branch": "master", "commit": "51059bcf21016387b6233c89eed220cf47fca752" }, "headlines.nvim": { "branch": "master", "commit": "618ef1b2502c565c82254ef7d5b04402194d9ce3" }, "image.nvim": { "branch": "master", "commit": "da64ce69598875c9af028afe129f916b02ccc42e" }, - "lazy.nvim": { "branch": "main", "commit": "b0ba3f9399bf48c86abaa4db1a40bd0b681d5018" }, + "lazy.nvim": { "branch": "main", "commit": "70f2c090d3ffb14f8702d468e05beb240b768881" }, "lsp-setup.nvim": { "branch": "main", "commit": "6e4e977512ce426d8b52c27f3b6e6aefc73e1452" }, "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, - "markdown-preview.nvim": { "branch": "master", "commit": "9becceee5740b7db6914da87358a183ad11b2049" }, "markmap.nvim": { "branch": "main", "commit": "5fb6755cf5434511cc23a4936c9eb76b9142fba5" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "9ae570e206360e47d30b4c35a4550c165f4ea7b7" }, "mason-tool-installer.nvim": { "branch": "main", "commit": "c5e07b8ff54187716334d585db34282e46fa2932" }, @@ -54,7 +53,7 @@ "nvim-colorizer.lua": { "branch": "master", "commit": "85855b38011114929f4058efc97af1059ab3e41d" }, "nvim-coverage": { "branch": "main", "commit": "aa4b4400588e2259e87e372b1e4e90ae13cf5a39" }, "nvim-lint": { "branch": "master", "commit": "1a3a8d047bc01f1760ae4a0f5e80f111ea222e67" }, - "nvim-lspconfig": { "branch": "master", "commit": "d1ab6b6051976b04948e127b0f302a465b1394d6" }, + "nvim-lspconfig": { "branch": "master", "commit": "92166b89ab4b3d60f24e58170cac53b7141fd032" }, "nvim-nio": { "branch": "master", "commit": "8765cbc4d0c629c8158a5341e1b4305fd93c3a90" }, "nvim-surround": { "branch": "main", "commit": "f1f0699a1d49f28e607ffa4361f1bbe757ac5ebc" }, "nvim-toggleterm.lua": { "branch": "main", "commit": "066cccf48a43553a80a210eb3be89a15d789d6e6" }, @@ -67,6 +66,7 @@ "nvim-ts-context-commentstring": { "branch": "main", "commit": "cb064386e667def1d241317deed9fd1b38f0dc2e" }, "nvim-web-devicons": { "branch": "master", "commit": "5b9067899ee6a2538891573500e8fd6ff008440f" }, "otter.nvim": { "branch": "main", "commit": "5cd161f28835fada50d99c89dc05041565a27bdb" }, + "peek.nvim": { "branch": "master", "commit": "5820d937d5414baea5f586dc2a3d912a74636e5b" }, "plenary.nvim": { "branch": "master", "commit": "50012918b2fc8357b87cff2a7f7f0446e47da174" }, "popup.nvim": { "branch": "master", "commit": "b7404d35d5d3548a82149238289fa71f7f6de4ac" }, "quarto-nvim": { "branch": "main", "commit": "67e09027b5d8bd948907734fc6fb15028ffdcd28" }, @@ -75,7 +75,7 @@ "stickybuf.nvim": { "branch": "master", "commit": "2160fcd536d81f5fa43f7167dba6634e814e3154" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "9ef21b2e6bb6ebeaf349a0781745549bbb870d27" }, "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, - "trouble.nvim": { "branch": "main", "commit": "46a19388d3507f4c4bebb9994bf821a79b3bc342" }, + "trouble.nvim": { "branch": "main", "commit": "7a9c235806d4d9e2e74889f7e359f183a6d0e20d" }, "twilight.nvim": { "branch": "main", "commit": "8bb7fa7b918baab1ca81b977102ddb54afa63512" }, "undotree": { "branch": "main", "commit": "eab459ab87dd249617b5f7187bb69e614a083047" }, "vifm.vim": { "branch": "master", "commit": "a8130c37d144b51d84bee19f0532abcd3583383f" }, @@ -85,7 +85,7 @@ "vim-pandoc-syntax": { "branch": "master", "commit": "16939cda184ff555938cc895cc62477c172997f9" }, "vim-scimark": { "branch": "master", "commit": "9b66a88fa4bb87b8baab3c4aecc43b985b32e7fd" }, "vim-spellsync": { "branch": "master", "commit": "3d6dd50de9c4d953cc16638112a6ae196df41463" }, - "which-key.nvim": { "branch": "main", "commit": "4b7167f8fb2dba3d01980735e3509e172c024c29" }, + "which-key.nvim": { "branch": "main", "commit": "0539da005b98b02cf730c1d9da82b8e8edb1c2d2" }, "wrapping.nvim": { "branch": "master", "commit": "3a823200c297885b70515fa8d974e1763c578e26" }, "zen-mode.nvim": { "branch": "main", "commit": "cb73b8bd0ef9d765b942db09dc762c603a89ae44" }, "zk-nvim": { "branch": "main", "commit": "66b9b490e930fb77f93a2a0c64e0da9a5144fd0a" } From 57f2fbd5fe84bca9f98b16023ece1705d73e7a30 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 7 Jun 2024 09:50:26 +0200 Subject: [PATCH 5/7] nvim: Replace vim-easy-align with mini module Mini.nvim now also comes with an align module which perfectly mimics the behavior of my beloved junegunn vim-easy-align plugin. It is almost sad to see such an old friend go, but ultimately it removes a redundant plugin and switches the setup ever so slightly more towards being lua based. The mini module also allows more advanced lua-based modifier pattern shenanigans but so far I don't need any of the advanced stuff: I just need a quick way to align markdown tables and similar, and this one does exactly the same as before, only with a couple nice additional options and previews. It still uses the same key chord `ga` but also offers `gA` which apparently comes with a nicer preview. My fingers will probably stick to the former for the time being. One thing that changes is that, by default, it will align *all* separators not just the first instance on each line. To mimic the old behavior you can, in alignment mode, hit `f` to enter a filter and enter `n==2` to get the same result as default vim-easy-align (the first pair of delimiters are aligned). Also it comes with some nice extra functionality like trimming whitespace by just hitting `t` when in alignment mode --- nvim/.config/nvim/lua/plugins/core.lua | 2 ++ nvim/.config/nvim/lua/plugins/editing.lua | 9 --------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/core.lua b/nvim/.config/nvim/lua/plugins/core.lua index 92414dc..4951e6e 100644 --- a/nvim/.config/nvim/lua/plugins/core.lua +++ b/nvim/.config/nvim/lua/plugins/core.lua @@ -107,6 +107,8 @@ return { }) require("mini.ai").setup() + -- Align tables and other alignable things + require("mini.align").setup({}) require("mini.comment").setup({ hooks = { pre = function() diff --git a/nvim/.config/nvim/lua/plugins/editing.lua b/nvim/.config/nvim/lua/plugins/editing.lua index 3d9fbda..d926dc0 100644 --- a/nvim/.config/nvim/lua/plugins/editing.lua +++ b/nvim/.config/nvim/lua/plugins/editing.lua @@ -1,13 +1,4 @@ return { - -- Align tables and other alignable things - { - "junegunn/vim-easy-align", - event = "InsertEnter", - keys = { - { "ga", "(EasyAlign)", mode = "n" }, - { "ga", "(EasyAlign)", mode = "x" }, - }, - }, -- surround things with other things using ys/cs/ds { "kylechui/nvim-surround", config = true, event = "VeryLazy" }, From 4f67a6d3cac11d1d2873a7ba1608012a679b74b5 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 7 Jun 2024 09:55:56 +0200 Subject: [PATCH 6/7] nvim: Fix which-key conditional usage if not loaded The only left-over which-key invocation which did not check for its existence beforehand. --- nvim/.config/nvim/lua/plugins/config/lsp.lua | 4 +++- nvim/.config/nvim/lua/plugins/git.lua | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/config/lsp.lua b/nvim/.config/nvim/lua/plugins/config/lsp.lua index aa63460..e84244e 100644 --- a/nvim/.config/nvim/lua/plugins/config/lsp.lua +++ b/nvim/.config/nvim/lua/plugins/config/lsp.lua @@ -70,7 +70,9 @@ local function on_attach(client, bufnr) { buffer = bufnr, desc = "Next error" } ) - require("which-key").register({ ["l"] = { name = "+language" } }) + if require("core.util").is_available("which-key") then + require("which-key").register({ ["l"] = { name = "+language" } }) + end map( "n", "ld", diff --git a/nvim/.config/nvim/lua/plugins/git.lua b/nvim/.config/nvim/lua/plugins/git.lua index b5414d1..cc24131 100644 --- a/nvim/.config/nvim/lua/plugins/git.lua +++ b/nvim/.config/nvim/lua/plugins/git.lua @@ -55,7 +55,9 @@ return { end, { expr = true, desc = "Previous git hunk" }) -- Actions - require("which-key").register({ ["h"] = { name = "+git" } }) + if require("core.util").is_available("which-key") then + require("which-key").register({ ["h"] = { name = "+git" } }) + end map({ "n", "v" }, "hs", ":Gitsigns stage_hunk", { desc = "stage hunk" }) map({ "n", "v" }, "hr", ":Gitsigns reset_hunk", { desc = "reset hunk" }) map("n", "hS", gs.stage_buffer, { desc = "stage buffer" }) From 6d82162f16b5f4a3607ba758b5d58f4029aad67e Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 7 Jun 2024 11:08:56 +0200 Subject: [PATCH 7/7] nvim: Switch basic file editor to mini.files While we can still reach vifm through the `E` mapping, the basic `e` file editor mapping has been switched over to the mini.files browser. It works somewhat like oil.nvim, in that you simply get a buffer to work with that you can delete/move/copy/rename lines in and after doing a synchronization (with `=`) all changes are actually applied to the files. Since I mostly need the quick file opening to do some quick renaming operation or want to open an adjacent file this seems like the quickest and most painless option to do so. For larger operations I still have access to the full vifm experience. --- nvim/.config/nvim/lua/plugins/core.lua | 65 +++++++++++++------ .../.config/nvim/lua/plugins/filebrowsers.lua | 5 +- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins/core.lua b/nvim/.config/nvim/lua/plugins/core.lua index 4951e6e..5579dbd 100644 --- a/nvim/.config/nvim/lua/plugins/core.lua +++ b/nvim/.config/nvim/lua/plugins/core.lua @@ -107,8 +107,27 @@ return { }) require("mini.ai").setup() - -- Align tables and other alignable things + -- Align tables and other alignable things require("mini.align").setup({}) + + require("mini.bracketed").setup({ + { + buffer = { suffix = "b", options = {} }, + comment = { suffix = "c", options = {} }, + conflict = { suffix = "", options = {} }, + diagnostic = { suffix = "d", options = {} }, + file = { suffix = "f", options = {} }, + indent = { suffix = "", options = {} }, -- disable since we use indentscope above + jump = { suffix = "j", options = {} }, + location = { suffix = "l", options = {} }, + oldfile = { suffix = "o", options = {} }, + quickfix = { suffix = "q", options = {} }, + treesitter = { suffix = "t", options = {} }, + undo = { suffix = "", options = {} }, -- disable since I don't need it + window = { suffix = "w", options = {} }, + yank = { suffix = "y", options = {} }, + }, + }) require("mini.comment").setup({ hooks = { pre = function() @@ -119,9 +138,19 @@ return { end, }, }) + require("mini.cursorword").setup({ delay = 500 }) vim.api.nvim_set_hl(0, "MiniCursorword", { bold = true, underline = false }) vim.api.nvim_set_hl(0, "MiniCursorwordCurrent", { bold = true, underline = false }) + + require("mini.files").setup() + vim.api.nvim_create_autocmd("User", { + pattern = "MiniFilesWindowUpdate", + callback = function(args) + vim.wo[args.data.win_id].number = true + end, + }) + require("mini.fuzzy").setup() require("mini.indentscope").setup({ symbol = "│", @@ -150,24 +179,6 @@ return { starter.gen_hook.aligning("center", "center"), }, }) - require("mini.bracketed").setup({ - { - buffer = { suffix = "b", options = {} }, - comment = { suffix = "c", options = {} }, - conflict = { suffix = "", options = {} }, - diagnostic = { suffix = "d", options = {} }, - file = { suffix = "f", options = {} }, - indent = { suffix = "", options = {} }, -- disable since we use indentscope above - jump = { suffix = "j", options = {} }, - location = { suffix = "l", options = {} }, - oldfile = { suffix = "o", options = {} }, - quickfix = { suffix = "q", options = {} }, - treesitter = { suffix = "t", options = {} }, - undo = { suffix = "", options = {} }, -- disable since I don't need it - window = { suffix = "w", options = {} }, - yank = { suffix = "y", options = {} }, - }, - }) end, event = "VimEnter", -- need to load pretty soon for Starter screen keys = { @@ -176,14 +187,16 @@ return { function() require("mini.map").toggle() end, - silent = true, desc = "minimap" , + silent = true, + desc = "minimap", }, { "ss", function() require("mini.starter").open() end, - silent = true, desc = "startpage" , + silent = true, + desc = "startpage", }, { "w", @@ -192,6 +205,16 @@ return { end, desc = "Trim trailing whitespace", }, + { + "e", + function() + local mf = require("mini.files") + if not mf.close() then + mf.open() + end + end, + desc = "floating file browser", + }, }, }, -- try to avoid putting files in util buffers, e.g. filetree, aerial, undotree, .. diff --git a/nvim/.config/nvim/lua/plugins/filebrowsers.lua b/nvim/.config/nvim/lua/plugins/filebrowsers.lua index 411f81b..b26f4c8 100644 --- a/nvim/.config/nvim/lua/plugins/filebrowsers.lua +++ b/nvim/.config/nvim/lua/plugins/filebrowsers.lua @@ -9,9 +9,8 @@ return { 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" }, + { "E", "Vifm", desc = "buffer file browser" }, + { "vc", ":Vifm " .. vim.fn.stdpath("config") .. "", desc = "open config" }, }, event = { "BufEnter" }, }, -- integrate file manager