gzip.vim 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. " Vim plugin for editing compressed files.
  2. " Maintainer: Bram Moolenaar <Bram@vim.org>
  3. " Last Change: 2016 Oct 30
  4. " Exit quickly when:
  5. " - this plugin was already loaded
  6. " - when 'compatible' is set
  7. " - some autocommands are already taking care of compressed files
  8. if exists("loaded_gzip") || &cp || exists("#BufReadPre#*.gz")
  9. finish
  10. endif
  11. let loaded_gzip = 1
  12. augroup gzip
  13. " Remove all gzip autocommands
  14. au!
  15. " Enable editing of gzipped files.
  16. " The functions are defined in autoload/gzip.vim.
  17. "
  18. " Set binary mode before reading the file.
  19. " Use "gzip -d", gunzip isn't always available.
  20. autocmd BufReadPre,FileReadPre *.gz,*.bz2,*.Z,*.lzma,*.xz,*.lz,*.zst setlocal bin
  21. autocmd BufReadPost,FileReadPost *.gz call gzip#read("gzip -dn")
  22. autocmd BufReadPost,FileReadPost *.bz2 call gzip#read("bzip2 -d")
  23. autocmd BufReadPost,FileReadPost *.Z call gzip#read("uncompress")
  24. autocmd BufReadPost,FileReadPost *.lzma call gzip#read("lzma -d")
  25. autocmd BufReadPost,FileReadPost *.xz call gzip#read("xz -d")
  26. autocmd BufReadPost,FileReadPost *.lz call gzip#read("lzip -d")
  27. autocmd BufReadPost,FileReadPost *.zst call gzip#read("zstd -d --rm")
  28. autocmd BufWritePost,FileWritePost *.gz call gzip#write("gzip")
  29. autocmd BufWritePost,FileWritePost *.bz2 call gzip#write("bzip2")
  30. autocmd BufWritePost,FileWritePost *.Z call gzip#write("compress -f")
  31. autocmd BufWritePost,FileWritePost *.lzma call gzip#write("lzma -z")
  32. autocmd BufWritePost,FileWritePost *.xz call gzip#write("xz -z")
  33. autocmd BufWritePost,FileWritePost *.lz call gzip#write("lzip")
  34. autocmd BufWritePost,FileWritePost *.zst call gzip#write("zstd --rm")
  35. autocmd FileAppendPre *.gz call gzip#appre("gzip -dn")
  36. autocmd FileAppendPre *.bz2 call gzip#appre("bzip2 -d")
  37. autocmd FileAppendPre *.Z call gzip#appre("uncompress")
  38. autocmd FileAppendPre *.lzma call gzip#appre("lzma -d")
  39. autocmd FileAppendPre *.xz call gzip#appre("xz -d")
  40. autocmd FileAppendPre *.lz call gzip#appre("lzip -d")
  41. autocmd FileAppendPre *.zst call gzip#appre("zstd -d --rm")
  42. autocmd FileAppendPost *.gz call gzip#write("gzip")
  43. autocmd FileAppendPost *.bz2 call gzip#write("bzip2")
  44. autocmd FileAppendPost *.Z call gzip#write("compress -f")
  45. autocmd FileAppendPost *.lzma call gzip#write("lzma -z")
  46. autocmd FileAppendPost *.xz call gzip#write("xz -z")
  47. autocmd FileAppendPost *.lz call gzip#write("lzip")
  48. autocmd FileAppendPost *.zst call gzip#write("zstd --rm")
  49. augroup END