gzip.vim 3.0 KB

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