cf9f5ab
" Vim plugin for editing compressed files.
cf9f5ab
" Maintainer: Bram Moolenaar <Bram@vim.org>
cf9f5ab
" Last Change: 2005 Jul 26
cf9f5ab
cf9f5ab
" Exit quickly when:
cf9f5ab
" - this plugin was already loaded
cf9f5ab
" - when 'compatible' is set
cf9f5ab
" - some autocommands are already taking care of compressed files
cf9f5ab
if exists("loaded_gzip") || &cp || exists("#BufReadPre#*.gz")
cf9f5ab
  finish
cf9f5ab
endif
cf9f5ab
let loaded_gzip = 1
cf9f5ab
cf9f5ab
augroup gzip
cf9f5ab
  " Remove all gzip autocommands
cf9f5ab
  au!
cf9f5ab
cf9f5ab
  " Enable editing of gzipped files.
cf9f5ab
  " The functions are defined in autoload/gzip.vim.
cf9f5ab
  "
cf9f5ab
  " Set binary mode before reading the file.
cf9f5ab
  " Use "gzip -d", gunzip isn't always available.
cf9f5ab
  autocmd BufReadPre,FileReadPre	*.gz,*.bz2,*.Z setlocal bin
cf9f5ab
  autocmd BufReadPost,FileReadPost	*.gz  call gzip#read("gzip -dn")
cf9f5ab
  autocmd BufReadPost,FileReadPost	*.bz2 call gzip#read("bzip2 -d")
cf9f5ab
  autocmd BufReadPost,FileReadPost	*.Z   call gzip#read("uncompress")
cf9f5ab
  autocmd BufWritePost,FileWritePost	*.gz  call gzip#write("gzip")
cf9f5ab
  autocmd BufWritePost,FileWritePost	*.bz2 call gzip#write("bzip2")
cf9f5ab
  autocmd BufWritePost,FileWritePost	*.Z   call gzip#write("compress -f")
cf9f5ab
  autocmd FileAppendPre			*.gz  call gzip#appre("gzip -dn")
cf9f5ab
  autocmd FileAppendPre			*.bz2 call gzip#appre("bzip2 -d")
cf9f5ab
  autocmd FileAppendPre			*.Z   call gzip#appre("uncompress")
cf9f5ab
  autocmd FileAppendPost		*.gz  call gzip#write("gzip")
cf9f5ab
  autocmd FileAppendPost		*.bz2 call gzip#write("bzip2")
cf9f5ab
  autocmd FileAppendPost		*.Z   call gzip#write("compress -f")
cf9f5ab
augroup END