From 2728b4efe03056a14c2c6b09f8186f9244e8cf58 Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Sun, 5 Oct 2025 19:17:50 +0300 Subject: [PATCH] feat(pack): add `[[` and `]]` mappings in confirmation buffer Problem: No easy/robust way to jump between plugin sections. Solution: Add `[[` and `]]` mappings. --- runtime/doc/pack.txt | 7 +++--- runtime/ftplugin/nvim-pack.lua | 13 +++++++++++ runtime/lua/vim/pack.lua | 6 +++-- test/functional/plugin/pack_spec.lua | 34 ++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/runtime/doc/pack.txt b/runtime/doc/pack.txt index 557f1bc762..4ea0e61c3f 100644 --- a/runtime/doc/pack.txt +++ b/runtime/doc/pack.txt @@ -393,9 +393,10 @@ update({names}, {opts}) *vim.pack.update()* • Depending on `force`: • If `false`, show confirmation buffer. It lists data about all set to update plugins. Pending changes starting with `>` will be applied - while the ones starting with `<` will be reverted. It has special - in-process LSP server attached to provide more interactive features. - Currently supported methods: + while the ones starting with `<` will be reverted. It has dedicated + buffer-local mappings: + • |]]| and |[[| to navigate through plugin sections. + Some features are provided via LSP: • 'textDocument/documentSymbol' (`gO` via |lsp-defaults| or |vim.lsp.buf.document_symbol()|) - show structure of the buffer. • 'textDocument/hover' (`K` via |lsp-defaults| or diff --git a/runtime/ftplugin/nvim-pack.lua b/runtime/ftplugin/nvim-pack.lua index 2929077255..78402b8d6f 100644 --- a/runtime/ftplugin/nvim-pack.lua +++ b/runtime/ftplugin/nvim-pack.lua @@ -1,3 +1,4 @@ +-- Highlighting local ns = vim.api.nvim_create_namespace('nvim.pack.confirm') vim.api.nvim_buf_clear_namespace(0, ns, 0, -1) @@ -49,3 +50,15 @@ for i, l in ipairs(lines) do hi_range(i, 4, l:len(), 'DiagnosticHint') end end + +-- Mappings +local map_section_jump = function(lhs, search_flags, desc) + vim.keymap.set({ 'n', 'x' }, lhs, function() + for _ = 1, vim.v.count1 do + vim.fn.search('^## ', search_flags) + end + end, { buffer = 0, desc = desc }) +end + +map_section_jump('[[', 'bsW', 'Previous plugin') +map_section_jump(']]', 'sW', 'Next plugin') diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua index 6790350bc3..35952243b9 100644 --- a/runtime/lua/vim/pack.lua +++ b/runtime/lua/vim/pack.lua @@ -957,8 +957,10 @@ end --- - If `false`, show confirmation buffer. It lists data about all set to --- update plugins. Pending changes starting with `>` will be applied while --- the ones starting with `<` will be reverted. ---- It has special in-process LSP server attached to provide more interactive ---- features. Currently supported methods: +--- It has dedicated buffer-local mappings: +--- - |]]| and |[[| to navigate through plugin sections. +--- +--- Some features are provided via LSP: --- - 'textDocument/documentSymbol' (`gO` via |lsp-defaults| --- or |vim.lsp.buf.document_symbol()|) - show structure of the buffer. --- - 'textDocument/hover' (`K` via |lsp-defaults| or |vim.lsp.buf.hover()|) - diff --git a/test/functional/plugin/pack_spec.lua b/test/functional/plugin/pack_spec.lua index 4ea9a0eca7..78da56ef86 100644 --- a/test/functional/plugin/pack_spec.lua +++ b/test/functional/plugin/pack_spec.lua @@ -1205,6 +1205,40 @@ describe('vim.pack', function() validate_hover({ 32, 0 }, 'Add version 0.3.1') end) + it('has buffer-local mappings', function() + t.skip(not is_jit(), "Non LuaJIT reports update errors differently due to 'coxpcall'") + exec_lua(function() + vim.pack.add({ + repos_src.fetch, + { src = repos_src.semver, version = 'v0.3.0' }, + { src = repos_src.defbranch, version = 'does-not-exist' }, + }) + -- Enable sourcing filetype script (that creates mappings) + vim.cmd('filetype plugin on') + vim.pack.update() + end) + + -- Plugin sections navigation + local validate = function(keys, ref_cursor) + n.feed(keys) + eq(ref_cursor, api.nvim_win_get_cursor(0)) + end + + api.nvim_win_set_cursor(0, { 1, 1 }) + validate(']]', { 3, 0 }) + validate(']]', { 11, 0 }) + validate(']]', { 24, 0 }) + -- - Should not wrap around the edge + validate(']]', { 24, 0 }) + + api.nvim_win_set_cursor(0, { 32, 1 }) + validate('[[', { 24, 0 }) + validate('[[', { 11, 0 }) + validate('[[', { 3, 0 }) + -- - Should not wrap around the edge + validate('[[', { 3, 0 }) + end) + it('suggests newer versions when on non-tagged commit', function() local commit = git_get_hash('0.3.1~', 'semver') exec_lua(function()