Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

migrated from stackoverflow.com Nov 20 '12 at 22:18

This question came from our site for professional and enthusiast programmers.

    
Vim is for text files. It does not unzip files or view compressed files. – jahroy Nov 20 '12 at 9:15
    
@jahroy: some vim distributions have autocmds for unzipping those files – Benoit Nov 20 '12 at 9:15
    
vim is a text editor. Not zip viewer. – Shiplu Nov 20 '12 at 9:15
1  
Ahmad, 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 Nov 20 '12 at 9:16
1  
@Ahmad you need to type that inside vim after pressing Esc. Not in ksh console. – Shiplu Nov 20 '12 at 9:31
up vote 6 down vote accepted

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

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

  • if the machine has the gzip program,
  • if you have the right permissions to use it,
  • if your Vim comes with the the gzip standard plugin which should be located at /usr/share/vim/vim7x/plugin/gzip.vim and its companion in /usr/share/vim/vim7x/autoload/gzip.vim.
share|improve this answer
1  
also needs autoload/gzip.vim – Benoit Nov 20 '12 at 9:44
    
You are right. I'll add it to my answer if you don't mind. – romainl Nov 20 '12 at 9:45
    
Can be a conflict between several plugins, for example file-line github.com/bogado/file-line/issues/56 – Ôrel Oct 9 '15 at 10:43

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.

share|improve this answer

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
share|improve this answer
1  
-1. vim with some autocmds, in some distributions, automatically gunzips the file at loading time and gzips them back before saving. – Benoit Nov 20 '12 at 9:19
    
+1. your suggestion are quite a help.. I want to see why its not working on my machine but works for others – Ahmad Nov 20 '12 at 9:23
    
@Ahmad do you have read permission to read that file? – Shiplu Nov 20 '12 at 9:24
    
@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 Nov 20 '12 at 9:25
    
@shiplu.mokadd.im: good remark. removing my -1. – Benoit Nov 20 '12 at 9:33

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

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .