55

When I have a file open in vim, in this case a log file, I'd like to trigger a refresh and load any file changes into my existing vim session.

I often use tail -f on log files, but as I'm using java and tomcat, the log messages are too much for tail...

Is there a vim command to reload an open file?

mcgyver5
  • 1,101
  • 3
    too much for tail? even as a vim user i dont see how vim can improve the situation ... – akira Feb 17 '11 at 17:40
  • too much for tail in that the number of lines was unpredictable so I couldn't be sure that tail -f n 200 would be enough – mcgyver5 Feb 17 '11 at 17:54
  • I've a log generated by modsecurity that contains non-ASCII characters. Both cat and tail lock the terminal when called on this file. Vim merrily chugs along. –  Oct 12 '14 at 17:15

2 Answers2

78

Give this a try:

:e

From :h :e:

Edit the current file. This is useful to re-edit the current file, when it has been changed outside of Vim.

16

While :e is the correct answer to the question you asked, if the goal is to tail a log with good scrollback, you can use less. F while viewing a file will scroll Forward, with continuous reloading. From the man page:

   F      Scroll  forward, and keep trying to read when the end of file
          is reached.  Normally this command would be used when already
          at the end of the file.  It is a way to monitor the tail of a
          file which is growing while it is being viewed.  (The  behav-
          ior is similar to the "tail -f" command.)

Less of an imposition on the user than rapidly :eing in vim.

to_json
  • 161
  • 1
  • 2
  • This is a better answer, IMHO. Though it technically doesn't answer the question asked, it's a better solution to his base problem. – Bdoserror Nov 22 '23 at 17:55