I have openend a zip archive with vim (zip.vim v27) and now want to replace a string in all files contained in the archive.

I'm aware that I could manually open all files in buffers and then do bufdo %s/foo/bar/g | update, or that I could unpack the archive, execute vim `find . -type f`, execute the above bufdo, and repack the files. Is there anything simpler than that?

1 Answer 1


One approach is to let your operating system mount the zip file as a directory. Then the problem reduces to applying the transformation to all the files in that directory (and its subdirectories).

Most modern Unix systems (including Linux and OS X) support FUSE, which allows user code to implement filesystems. For example, you can use [fuse-zip]:

  1. Create an empty directory where the zip file will be mounted.

    mkdir mnt
  2. Mount the zip file to that directory.

    fuse-zip foo.zip mnt
  3. Read and modify files in mnt as desired.

  4. When you're done, unmount the zip file from the directory.

    fusermount -u mnt

An alternative to fuse-zip is archivemount. Windows has a somewhat similar feature that allows mounting a zip file as a drive with third-party software.

To act on all the files in a directory tree, you can use :args and :argdo.

:args mnt/**/*
:argdo %s/foo/bar/g | update
  • 3
    Note that fuse-zip wil stores all changed & added files in memory, and writes them to the zip file on unmount. This is why it's so fast. But has the obvious downsides that 1) It uses a lot of memory with many changes, and 2) it's vital that you don't forget to umount! (which may be a problem if fuse-zip gets killed when the system runs out of memory due to 1). Sep 9, 2015 at 23:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.