tail like functionality for gvim
Asked Answered
B

4

27

I want to use gvim to view a log file which is being updated continuously, such that I always see the last updated line, much like tail command in unix. Is it possible?

Batsheva answered 15/5, 2009 at 9:22 Comment(2)
possible duplicate of Using VIM as a logfile-viewerGrenoble
This specifies gvim, the other is vim. This solution does not work for vim, so it is a separate question AND a separate answer. NOT a duplicate.Finished
D
43

Open logfile and

:setlocal autoread

There is a plugin (Tail Bundle) on the vim site.

Devon answered 15/5, 2009 at 9:24 Comment(1)
how do I use the Tail Bundle plugin? I've looked at the docs and none of them seem to make the file continuously load?Pileate
C
8

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)

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

Chuckle answered 18/1, 2018 at 8:6 Comment(0)
S
2

Or a less elegant solution on a vim 7.x would be just do :e! whenever you need the update .

Sequestrate answered 22/5, 2012 at 22:9 Comment(2)
Sorry for flagging this answer, but this is exactly what Canopus was trying NOT to do... "being updated continuously, such that I alway see the last updated line" is not solved by :e! whenever you need the update.Selfanalysis
acknowledged, will look into questions posted more carefully.Sequestrate
O
0

I would suggest to just open term in vim using :term and run tail -f from there :)

Oconner answered 23/7, 2024 at 10:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.