I'd like to use VIM as a logfile-viewer. Is it possible to reload the current file in a regular time interval (~1s)?
-
What advantage does vim give you over, say, "less -F"? – Paul Tomblin Apr 24 '09 at 11:27
-
3Pretty syntax highlighting. (e.g. I can color ERROR-level messages red). I have to use it under Windows. – Apr 24 '09 at 11:46
-
1And highlighted incremented search. – Mykola Golubyev Nov 20 '09 at 08:57
-
Does this answer your question? [Can vim monitor realtime changes to a file](https://stackoverflow.com/questions/2157914/can-vim-monitor-realtime-changes-to-a-file) – user202729 Dec 09 '21 at 15:47
5 Answers
use :set autoread

- 114,645
- 34
- 221
- 317
-
1This will only update the file when (g)vim has focus though. It also won't scroll to the bottom automatically. So it's not really all that useful. – rkrzr Feb 17 '14 at 13:16
-
@rkrzr if you have a better option please feel free to provide an answer and I'll be glad to upvote. – Brian Rasmussen Feb 17 '14 at 15:51
-
1For me it didn't even update the file when vim had focus. (I'm on Windows 7 with VIM 7.3 2010 August 15.) In order to get it to update I had to put another window into focus and then click back into gVIM. – feuGene Mar 26 '14 at 11:58
See this VIM tip. It offers tailing (like tail -f) together with log line numbering

- 268,207
- 37
- 334
- 440
-
From the description, it looks like this plugin has problems under Windows and in any case updates only when the cursor is moved in Vim. Is this correct? – Don Reba Apr 27 '09 at 04:30
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")
(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 inupdatetime
(which is 4000 miliseconds by default)checktime
is executed, which checks for changes from outside the filecall feedkeys("lh")
: the cursor is moved once, right and back left. and then nothing happens (... which means, thatCursorHold
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)

- 2,366
- 1
- 24
- 27
With the timers in Vim 8 this can now much simpler and less of a kludge. For example:
:set autoread
:function! Tailf(id)
: checkt
: $
:endfunc
:let timer_id = timer_start(4000, 'Tailf', {"repeat":-1})
This has vim rereading the whole log every 4 seconds. For many purposes that's fine, but would not be for large, say several GB, log files. There's other capabilities, like jobs and channels, that could be used for more sophisticated log reading.

- 133
- 2
- 6
asyncrun.vim lets you run programs and see live output in the quickfix (essentially JohnLittle's answer, but with setqflist()
instead of Tailf()
). You can use it with tail
(I'm on Windows and my tail
comes from my git install):
AsyncRun tail -f C:\logs\plugin-info.log
It has the additional benefit of using 'errorformat' to parse filenames out of the logs.

- 10,975
- 5
- 66
- 107