refactor(zip)!: builtin zip.lua plugin #40846

Problem:
The bundled `zip` plugin is implemented in Vimscript, making it harder to
maintain and build on with Nvim's Lua runtime infrastructure.

Solution:
Add an opt-out `zip.lua` browser backed by `nvim.dir`, and disable the legacy
Vimscript implementation by moving it to `pack/dist/opt/zip/`. Load it with
`:packadd zip`.
This commit is contained in:
Barrett Ruth authored and GitHub committed 2026-07-29 12:54:43 -04:00
1 parent 1dbc766fa7
commit e29af9c32f
18 files changed
+1001 -17

No files matched your search

+5 -1
View File
@@ -61,7 +61,11 @@ vim.api.nvim_create_autocmd('BufReadCmd', {
end
if archive_kind == 'zip' then
vim.fn['zip#Browse'](tmpfile)
if vim.fn.exists('#zip') == 1 then
vim.fn['zip#Browse'](tmpfile)
elseif vim.fn.exists('#nvim.zip') == 1 then
require('nvim.zip').browse(ev.buf, tmpfile)
end
else
vim.fn['tar#Browse'](tmpfile)
end
+108
View File
@@ -0,0 +1,108 @@
if vim.g.loaded_nvim_zip_plugin ~= nil or vim.fn.exists('#zip') == 1 then
return
end
vim.g.loaded_nvim_zip_plugin = true
local api = vim.api
-- Extension aliases inherited from the legacy plugin:
-- https://github.com/neovim/neovim/blob/7ba955fe079d4aa2554fea8e7235651fafd40efb/runtime/plugin/zipPlugin.vim#L34-L35
---@type string[]
local extensions = {
'aar',
'apk',
'cbz',
'celzip',
'crtx',
'docm',
'docx',
'dotm',
'dotx',
'ear',
'epub',
'gcsx',
'glox',
'gqsx',
'ja',
'jar',
'kmz',
'odb',
'odc',
'odf',
'odg',
'odi',
'odm',
'odp',
'ods',
'odt',
'otc',
'otf',
'otg',
'oth',
'oti',
'otp',
'ots',
'ott',
'oxt',
'pkpass',
'potm',
'potx',
'ppam',
'ppsm',
'ppsx',
'pptm',
'pptx',
'sldx',
'thmx',
'vdw',
'war',
'whl',
'wsz',
'xap',
'xlam',
'xlsb',
'xlsm',
'xlsx',
'xltm',
'xltx',
'xpi',
'zip',
}
---@type string[]
local archive_patterns = {}
for _, extension in ipairs(extensions) do
archive_patterns[#archive_patterns + 1] = ('*.%s'):format(extension)
end
local group = api.nvim_create_augroup('nvim.zip', { clear = true })
---@return boolean
local function legacy_loaded()
return vim.fn.exists('#zip') == 1
end
api.nvim_create_autocmd('BufReadCmd', {
group = group,
pattern = 'zipfile://*',
desc = 'Read zip archive entry',
callback = function(ev)
if legacy_loaded() then
return true
end
require('nvim.zip').read(ev.buf, ev.match)
end,
})
api.nvim_create_autocmd('BufReadCmd', {
group = group,
pattern = archive_patterns,
desc = 'Browse zip archives',
callback = function(ev)
if legacy_loaded() then
return true
end
if ev.match:match('^%a[%w+.-]*://') then
return
end
require('nvim.zip').browse(ev.buf, ev.match)
end,
})
-61
View File
@@ -1,61 +0,0 @@
" zipPlugin.vim: Handles browsing zipfiles
" PLUGIN PORTION
" Date: Dec 07, 2021
" Maintainer: This runtime file is looking for a new maintainer.
" Former Maintainer: Charles E Campbell
" Last Change:
" 2025 Apr 02 by Vim Project: add *.whl to list of zip extensions (#17038)
" 2025 Oct 06 by MultisampledNight: add *.pkpass to list of zip extensions (#18501)
" 2026 May 16 by Vim Project: add .cbz extension (#20206)
" License: Vim License (see vim's :help license)
" Copyright: Copyright (C) 2005-2016 Charles E. Campbell {{{1
" Permission is hereby granted to use and distribute this code,
" with or without modifications, provided that this copyright
" notice is copied with it. Like anything else that's free,
" zipPlugin.vim is provided *as is* and comes with no warranty
" of any kind, either expressed or implied. By using this
" plugin, you agree that in no event will the copyright
" holder be liable for any damages resulting from the use
" of this software.
"
" (James 4:8 WEB) Draw near to God, and he will draw near to you.
" Cleanse your hands, you sinners; and purify your hearts, you double-minded.
" ---------------------------------------------------------------------
" Load Once: {{{1
if &cp || exists("g:loaded_zipPlugin")
finish
endif
let g:loaded_zipPlugin = "v33"
let s:keepcpo = &cpo
set cpo&vim
" ---------------------------------------------------------------------
" Options: {{{1
if !exists("g:zipPlugin_ext")
let g:zipPlugin_ext='*.aar,*.apk,*.cbz,*.celzip,*.crtx,*.docm,*.docx,*.dotm,*.dotx,*.ear,*.epub,*.gcsx,*.glox,*.gqsx,*.ja,*.jar,*.kmz,*.odb,*.odc,*.odf,*.odg,*.odi,*.odm,*.odp,*.ods,*.odt,*.otc,*.otf,*.otg,*.oth,*.oti,*.otp,*.ots,*.ott,*.oxt,*.pkpass,*.potm,*.potx,*.ppam,*.ppsm,*.ppsx,*.pptm,*.pptx,*.sldx,*.thmx,*.vdw,*.war,*.whl,*.wsz,*.xap,*.xlam,*.xlsb,*.xlsm,*.xlsx,*.xltm,*.xltx,*.xpi,*.zip'
endif
" ---------------------------------------------------------------------
" Public Interface: {{{1
augroup zip
au!
au BufReadCmd zipfile:* call zip#Read(expand("<amatch>"), 1)
au FileReadCmd zipfile:* call zip#Read(expand("<amatch>"), 0)
au BufWriteCmd zipfile:* call zip#Write(expand("<amatch>"))
au FileWriteCmd zipfile:* call zip#Write(expand("<amatch>"))
if has("unix")
au BufReadCmd zipfile:*/* call zip#Read(expand("<amatch>"), 1)
au FileReadCmd zipfile:*/* call zip#Read(expand("<amatch>"), 0)
au BufWriteCmd zipfile:*/* call zip#Write(expand("<amatch>"))
au FileWriteCmd zipfile:*/* call zip#Write(expand("<amatch>"))
endif
exe "au BufReadCmd ".g:zipPlugin_ext.' call zip#Browse(expand("<amatch>"))'
augroup END
" ---------------------------------------------------------------------
" Restoration And Modelines: {{{1
" vim: fdm=marker
let &cpo= s:keepcpo
unlet s:keepcpo