9

In this question, Gilles answered

Yet another possibility is to run tail -f in an Emacs shell buffer and use Emacs's syntax coloring abilities.

Because I'm a vim user, I'd like to do this with vim, not emacs.
Does vim have this feature?

  • 2
    Vim is just a text editor, unlike Emacs... There is, however, a tail plugin for Vim that may be of use. – jasonwryan Jun 25 '12 at 2:09
  • There is also the vimpager plug-in that might do the trick – bsd Jun 26 '12 at 10:58
  • 1
    does it have to be a text editor? If you just need to color text, you can use Clide – golimar Jun 27 '12 at 14:44
  • Additionally, there is TailBundle for vim. – jofel Jul 2 '12 at 14:23
  • There is a similar question here. The solutions explains the use of multitail and how to configure it, maybe it can be useful. – logoff Jul 27 '12 at 12:53
2

You can write a multithread plugin to change the buffer(s) in real time in Python or any other script that Vim supports and has threads.

But this only works in terminal as far as I know. At least in X11, the GUI version will crash if the GUI is modified by another thread.

If you accept other programs, grc and ccze are able to colorize streams.

0

I like it short and without a lot of hacking or external scripts. You can run this oneliner from ex (whithin vim) when needed (or put each command in vimrc, for when log-files are opened.)

:set autoread | au CursorHold * checktime | call feedkeys("lh")

and additionally you can :set syntax=logtalk to color the log

(if you would want to jump (nearly) to the end of the file, just use "G" instead of "lh" with feedkeys)

Explanation:

  • autoread: reads the file when changed from the outside (but it doesnt work on its own, there is no internal timer or something like that. It will only read the file when vim does an action, like a command in ex :!
  • CursorHold * checktime: when the cursor isn't moved by the user for the time specified in updatetime (which is 4000 miliseconds by default) checktime is executed, which checks for changes from outside the file
  • call feedkeys("lh"): the cursor is moved once, right and back left. and then nothing happens (... which means, that CursorHold is triggered, which means we have a loop)

To stop the scrolling when using call feedkeys("G"), execute :set noautoread - now vim will tell, that the file was change ans ask if one wants to read the changes or not)

I like the idea to watch logfiles in vim (instead of tail -f), e.g. when you are working in an ssh session without screen/tmux. Additionally you can copy directly from the logfile, if needed, or save the output directly or ... whatever you can do with vim :)

*from this answer (refering to an answer by PhanHaiQuang and a comment by flukus)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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