How to open gzip text files in Gvim without unzipping?

回眸只為那壹抹淺笑 提交于 2019-12-03 01:31:57
Jean

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

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.

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.

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.

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