How to open gzip text files in Gvim without unzipping?

半城伤御伤魂 提交于 2019-12-04 08:59:03

问题


How to open Gzipped text files (*.gz) in Gvim without unzipping them first ?


回答1:


Solution mentioned in VimDocs as answered by therefromwhere

augroup gzip
 autocmd!
 autocmd BufReadPre,FileReadPre *.gz set bin
 autocmd BufReadPost,FileReadPost   *.gz '[,']!gunzip
 autocmd BufReadPost,FileReadPost   *.gz set nobin
 autocmd BufReadPost,FileReadPost   *.gz execute ":doautocmd BufReadPost " . expand("%:r")
 autocmd BufWritePost,FileWritePost *.gz !mv <afile> <afile>:r
 autocmd BufWritePost,FileWritePost *.gz !gzip <afile>:r
 autocmd FileAppendPre      *.gz !gunzip <afile>
 autocmd FileAppendPre      *.gz !mv <afile>:r <afile>
 autocmd FileAppendPost     *.gz !mv <afile> <afile>:r
 autocmd FileAppendPost     *.gz !gzip <afile>:r
augroup END



回答2:


Vim should do this for you automatically. At least it does for me. There's also zless. I'll see if I can find a resource that talks about how vim does this.




回答3:


There's a example in the vim docs how how to get this working: http://vimdoc.sourceforge.net/htmldoc/autocmd.html#gzip-example

For what it's worth I didn't need to do this on Ubuntu 10.04 (vim v7.2), it worked out of the box.




回答4:


Opening them directly would just give you the raw binary compressed data. There's tools for everything, but they need to be used appropriately. Sledgehammers are not there to break eggs for breakfast, and text editors aren't there to unzip.



来源:https://stackoverflow.com/questions/5396363/how-to-open-gzip-text-files-in-gvim-without-unzipping

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!