Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

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
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top