8

vim proj.dia gives binary data.

If renamed, vim opens it by unzipping:

$ mv proj.dia proj.dia.gz
$ vim proj.dia.gz

How to make the .dia act the same as .gz?

9

If we look at /usr/share/vim/vim80/plugin/gzip.vim we can see how the plugin does this:

augroup gzip
  " Remove all gzip autocommands
  au!

  " Enable editing of gzipped files.
  " The functions are defined in autoload/gzip.vim.
  "
  " Set binary mode before reading the file.
  " Use "gzip -d", gunzip isn't always available.
  autocmd BufReadPre,FileReadPre      *.gz,*.bz2,*.Z,*.lzma,*.xz,*.lz setlocal bin
  autocmd BufReadPost,FileReadPost    *.gz  call gzip#read("gzip -dn")
  autocmd BufWritePost,FileWritePost  *.gz  call gzip#write("gzip")
  autocmd FileAppendPre               *.gz  call gzip#appre("gzip -dn")
  autocmd FileAppendPost              *.gz  call gzip#write("gzip")
augroup END

There are other file extensions here as well (bzip2, xz, etc.) but I removed those for brevity's sake.

To add your own commands to this, you can add this to your vimrc file:

augroup gzip_local
    autocmd!
    autocmd BufReadPre,FileReadPre     *.dia setlocal bin
    autocmd BufReadPost,FileReadPost   *.dia call gzip#read("gzip -dn -S .dia")
    autocmd BufWritePost,FileWritePost *.dia call gzip#write("gzip -S .dia")
    autocmd FileAppendPre              *.dia call gzip#appre("gzip -dn -S .dia")
    autocmd FileAppendPost             *.dia call gzip#write("gzip -S .dia")
augroup END

We need to add the -S .dia option to get gzip to read and write to *.dia files, rather than *.gz files. As near as I can see most common platforms (Linux, {Free,Open}BSD, OSX) support this option, but some may not (in which case you'll have to write a wrapper script to move the file before decompressing and after compressing).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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