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.