How do I make Vim transparently edit .gz files using built-in tooling?
Answer
:packadd gzip
Explanation
Compressed logs and artifacts often appear in debugging workflows, and repeatedly shelling out to decompress and recompress wastes time. Vim ships with a gzip plugin that can transparently read and write .gz files so you edit them like normal buffers. Loading it explicitly with :packadd gzip gives you predictable behavior even in minimal setups.
How it works
:packadd gziploads Vim's optional gzip package from the runtime- On read, gzip-compressed files are decompressed into the buffer
- On write, content is recompressed back to
.gzformat
:packadd gzip
Example
Before:
server.log.1.gz
Open it after loading gzip support, edit a line, then :write:
Vim handles decompress/edit/recompress transparently
This keeps your pipeline simple and avoids temporary uncompressed copies.
Tips
- Add
packadd gzipto your config if you regularly inspect compressed logs - Run
:scriptnamesto confirm the plugin was loaded - Related built-ins (
tar,zip,matchit) can also be loaded via:packaddwhen needed