[Ilugc] Log file viewing help

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Mon Oct 23 17:19:40 2006

On Thu, Oct 19, 2006 at 12:49:00PM +0530, Girish Venkatachalam wrote:

Is there some way to open a continuously getting updated file(such as
production log file) in 'vi' editor so that I can go up and down the page
of the file. At the same time the file/buffer should also get updated with
the latest changes(may be by key press like ctrl-R or similar) but without
the need to close and open the file.
You are better off writing a vim script. I just took a look at it and looks 
simple to me. But unfortuately I have not written one for your need. If you 
need help please let me know. I may be able to do it. But you can too! :-)
This is what I have done. Please find the script attached. :-)

Also How can I open multiple file by spliting the vi screen(without using
splitvt tool) so that I can see and scroll different log files
simultaneoulsy in a single screen and in a single session.
vim 7.0 has a nice tabbed feature.

$vim -p file1 file2

And you can very easily switch between tabs using "gt" hotkey.

i.e, press g followed by t in command mode. 

It is really hard explaining vi in English. :-)

If you don't have 7.0, it is very easy to compile it urself. It has few other 
nice features as well. Just a straight configure make make install works.
Well now the instructions are different. Yank my script to a file that you call 
say tailtab.vim or something. The name really doesnt matter.

Now, execute these steps as a normal user.

$mkdir -p ~/.vim/plugin
$cp tailtab.vim ~/.vim/plugin

Now, just fire up vim 

$vim

Inside vim, type :TailView /var/log/messages /var/log/mail.log

to view these two files in separate tabs.

But system files are usually not allowed for viewing by normal users. I leave 
it an exercise what you have to do. :-)

TailView is to be entered in : mode just like :wq .

I am sure you get the idea.

Now, you can simultaneously edit another file since this plugin opens new tabs. 
Doesn't overwrite existing ones.

Press Ctrl-R to reload the file. You can of course at any time add new log 
files for monitoring using the TailTab command.

Of course you can use the usual TAB key for filename completion. :-)

Enjoy!

regards,
Girish

PS:- The file is 50 lines, so if you pay me 20$ per line, then it works out to 
1000$. Send a check and support a poor hacker! :-)

<<<<<<<<<<<<<<cut here>>>>>>>>>>>>>>>>>

" tailtab.vim
" Author: Girish Venkatachalam girish1729@xxxxxxxxx
" Description: 
"  A simple way to observe the new lines getting appended to text file
"  and also moving up and down the buffer.
"  
"  The requirement hopefully fulfilled by this script is that of
"  viewing multiple log files simultaneously
"  This will work on vim 7.0 and above
"
" License: Public domain
"
" Do whatever you want with it! 
"
" Usage is :TailView file1 file2 ... fileN
"
" You can also at any time add new files with the same command
" Each file will open a new tab, so obviously this plugin
" works only on vim versions above 7.0
"
" Enjoy!

if exists('loaded_tailtab') || &cp
        finish
endif

let loaded_tailtab = 1

if v:version < 700
        finish
endif



function! s:TailUpdate(file)
        tabnew
        exe 'edit'. a:file
        noremap  :e %<CR> 

endfunction

function! s:TailView(arg,...)
        echohl Title
        call s:TailUpdate(a:arg)
        let index = 1
        while index <= a:0
              call s:TailUpdate(a:{index})
              let index += 1
        endwhile
        echohl None
endfunction

command! -nargs=* -complete=file TailView call s:TailView(<f-args>)

<<<<<<<<<<<<<<cut here>>>>>>>>>>>>>>>>>

Other related posts: