Open a docx file as a zip in vim
Asked Answered
O

2

17

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?

Overbold answered 13/3, 2014 at 18:34 Comment(0)
O
20

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.

Overbold answered 13/3, 2014 at 18:34 Comment(3)
Is there a command-line option, so that we don't have to customize a vimrc file?Koosis
Thanks, TankorSmash. I was hoping that it might be something short like :e ++ff=dos to have vim recognize that the current file is in DOS format. But a long command is still helpful. I also found that vim automatically recognizes *.xlsx files as zip archives, but not *.xls files. The latter might not be vim's fault. Even unzip -l *.xls yields some funny results.Koosis
But such solution do not allow saving?Kerguelen
D
0

I just started to use https://github.com/lbrayner/vim-rzip, which also provides support for browsing zip-format files recursively, meaning if you have a zip inside the zip it also opens and you can navigate further down the tree.

You can define any file extension in the .vimrc, like this:

echo "let g:rzipPlugin_extra_ext = '*.jar,*.war,*.ear'" >> ~/.vimrc
Dharma answered 8/10, 2021 at 14:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.