Vim is not reading gzipped files automatically

4

I want to see some zipped log files .gz in unix through putty. When I open them in vim the contents are not readable. I think vim is not able to unzip them.

Ahmad

Posted 2012-11-20T09:13:20.057

Reputation: 199

Vim is for text files. It does not unzip files or view compressed files. – jahroy – 2012-11-20T09:15:38.750

@jahroy: some vim distributions have autocmds for unzipping those files – Benoit – 2012-11-20T09:15:57.630

vim is a text editor. Not zip viewer. – Shiplu Mokaddim – 2012-11-20T09:15:58.637

1Ahmad, can you tell us what vim says when you type :autocmd? Is there anything about .gz files? I for example have :autocmd BufRead *.gz call gzip#read("gzip -dn"). Do you have gzip executable, and this autocmd? – Benoit – 2012-11-20T09:16:23.447

@Benoit..@jahroy..my colleagues are able to see it..how ever they too are facing this problem sometime.. – None – 2012-11-20T09:18:26.827

@Benoit..I just need to type ":autocmd?"...right? – None – 2012-11-20T09:20:26.370

@Ahmad: type :autocmd BufRead *.gz and tell me whether you see what I saw (call gzip#read...) – Benoit – 2012-11-20T09:22:59.297

@Benoit..."ksh: :autocmd: not found"..I typed ":autocmd BufRead .log.gz".... being my file name – None – 2012-11-20T09:25:24.387

1@Ahmad you need to type that inside vim after pressing Esc. Not in ksh console. – Shiplu Mokaddim – 2012-11-20T09:31:08.133

@Benoit...it said "3 files to edit"...but it didn't show the content – None – 2012-11-20T09:35:30.253

don't type .log.gz but *.gz – Benoit – 2012-11-20T09:39:29.337

Answers

10

Vim is perfectly able to open gzipped files by default, see :help gzip.

If it's not possible in your case, you should see:

romainl

Posted 2012-11-20T09:13:20.057

Reputation: 19 227

1

Can be a conflict between several plugins, for example file-line https://github.com/bogado/file-line/issues/56

– Ôrel – 2015-10-09T10:43:44.427

Also, I just figured out... you can't view gzipped files with 'view', presumably because 'view' puts vim into compatible mode. – Todd Walton – 2019-08-08T12:14:14.633

1also needs autoload/gzip.vim – Benoit – 2012-11-20T09:44:38.713

You are right. I'll add it to my answer if you don't mind. – romainl – 2012-11-20T09:45:39.487

2

Reading compressed files transparently is handled by the gzip vim plugin. This plugin is only enabled when vim is not in "compatible" mode (see :help compatible for more details). An easy way to ensure "compatible" is not set, is to create an empty .vimrc file in your home directory.

Aner

Posted 2012-11-20T09:13:20.057

Reputation: 271

-1

Make sure you are really using vim and not vi. vi does not automatically open a gzipped file.

You could add an alias in bash: alias vi='vim'

To make the alias permanent, add it to ~/.bashrc

Mike

Posted 2012-11-20T09:13:20.057

Reputation: 1

-2

Vim is used for text editing. It can not open zip files.

I want to see some zipped log files .gz in unix through putty.

To see .gz file contents in command line use this command.

 zless /path/to/file.gz

If zless is not available use gunzip and less with a pipe

gunzip -c /path/to/file.gz | less

Shiplu Mokaddim

Posted 2012-11-20T09:13:20.057

Reputation: 647

2-1. vim with some autocmds, in some distributions, automatically gunzips the file at loading time and gzips them back before saving. – Benoit – 2012-11-20T09:19:25.530

+1. your suggestion are quite a help.. I want to see why its not working on my machine but works for others – None – 2012-11-20T09:23:23.707

@Ahmad do you have read permission to read that file? – Shiplu Mokaddim – 2012-11-20T09:24:30.533

@Benoit OP said I want to see some zipped log files .gz in unix through putty. And this is the answer. Besides, to only read something using vim is bad idea. – Shiplu Mokaddim – 2012-11-20T09:25:52.730

@shiplu.mokadd.im: good remark. removing my -1. – Benoit – 2012-11-20T09:33:23.640