Search code examples
vimzipdocx

Open a docx file as a zip in vim


I've got a docx file, which is really just a zip but since the extension isn't .zip, vim fails to recognize that, and opens the raw data.

I've tried opening the file and setting the filetype to zip, :set filetype=zip, I've tried opening the file as a directory, :e path/to/file.docx/ and I've tried opening the file

Is there any way that I can force vim to open the docx as a zip?


Solution

  • Naturally, within seconds of asking I do a :help zip and find the pi_zip plugin which explicitly tells me:

       Apparently there are a number of archivers which generate zip files that
       don't use the .zip extension (.jar, .xpi, etc).  To handle such files,
       place a line in your <.vimrc> file: >
    
        au BufReadCmd *.jar,*.xpi call zip#Browse(expand("<amatch>"))
    
       One can simply extend this line to accommodate additional extensions that
       should be treated as zip files.
    

    Which I can use to add the filetype to that list, and then also showed me

     au BufReadCmd *.docx call zip#Browse(expand("<amatch>"))
    

    or alternatively

     call zip#Browse(expand("/path/to/file"))
    

    which I can use explicitly if I don't want to always open a docx like that.

    If error on writing: check file permission, maybe it root:root.