vimtricks.wiki Concise Vim tricks, one at a time.

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 gzip loads 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 .gz format
: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 gzip to your config if you regularly inspect compressed logs
  • Run :scriptnames to confirm the plugin was loaded
  • Related built-ins (tar, zip, matchit) can also be loaded via :packadd when needed

Next

How do I configure quickfix parsing for grep output with file, line, and column?