Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

As a log viewer, which of vim's features are convenient?

less -F is quite good. But I believe vim could be better if we knew its hidden features.

* or #
v//d
g//d
etc..

PS. I don't use vim as a code writing tool.

share|improve this question

migrated from stackoverflow.com May 31 '10 at 7:02

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

    
It is well known that, we developers, never analyse million lines of log, that we never need a rich tool for that purpose in our development process. I guess that the reason why this post was migrated from SO... –  Luc Hermitte May 31 '10 at 9:00

5 Answers 5

up vote 4 down vote accepted

This probably goes without saying but if you're using log files that are overwritten regularly, then you'll want to:

:set autoread

so vim will keep the latest log up on screen at all times.

share|improve this answer
1  
Yes, I know the option. But the option never works at my machine(Both Windows and linux). Do you know why? –  Benjamin May 31 '10 at 2:46
1  
I run it through gvim under WinXP & it picks up the file changes when the window receives focus (e.g. when alt-tabbing back). I'm not sure how it works on the CLI but there's a bit more info in this thread: stackoverflow.com/questions/2490227/how-does-vims-autoread-work –  Mark McDonald May 31 '10 at 5:03

What makes it convenient? You've got all the power of vim, of course ... I could recommend the LargeFile plugin, though, such that vim doesn't slow down for large log files.

I use vim to search through large log files, using regexps, and sometimes for specific keywords with *, or sometimes create a copy by selecting only specific lines (e.g. :v//delete), and using block select to get some specific columns in the log output (since log lines mostly follow a specific format). Easiest way to create a quick table, IMHO.

share|improve this answer

IMO the only thing more you're going to get out of using vim as a pager is syntax highlighting if there is a syntax file for the particular log/file you're viewing. You can try out this sh script which does exactly that:

http://www.vim.org/scripts/script.php?script_id=1723

Although it lacks some of less's built in and useful features such as -F, it's not surprising considering vim was designed to be a text editor not a pager.

share|improve this answer
    
I've applied at my machine. But why doesn't vimpager read automatically a dynamic file? –  Benjamin May 31 '10 at 2:53

For long lines (not only in log files) scrolling horizontally is convenient. From my ~/.vimrc :

"-----------------------------------------------------------
" scroll horizontally     {{{2
"-----------------------------------------------------------
nnoremap <M-Left>  zH
nnoremap <M-Right> zL
inoremap <M-Left>  <Esc>zHi
inoremap <M-Right> <Esc>zLa
share|improve this answer

You could try the LogViewer plugin for viewing multiple parallel log files. While you can use tmux and tail to have a terminal display multiple log files, you won't have your cursor synchronized between the different panes.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.