Saturday, July 17, 2021

How to open the .gz file in gvim editor ?

 

    Right now, we can open session.log.gz file in gvim from the command line and it will unzip automatically & will show correct contents of the session.log  whereas if you try to open the same file from gvim editor itself, it won’t unzip.

 

If you add the following code to your .vimrc, it will fix that problem.

 

 

: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

No comments:

Post a Comment