Reload file in vim

53

13

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

Posted 2011-02-17T17:36:40.207

Reputation: 1 031

Question was closed 2014-12-18T12:29:49.727

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. – None – 2014-10-12T17:15:21.050

2too much for tail? even as a vim user i dont see how vim can improve the situation ... – akira – 2011-02-17T17:40:03.333

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 – 2011-02-17T17:54:56.913

Answers

71

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.

Paused until further notice.

Posted 2011-02-17T17:36:40.207

Reputation: 86 075

or go to end of file as well... :e | $ – ebyrob – 2017-02-23T20:14:02.163

thanks! I thought at one point :e wasn't working for me but it works now! – mcgyver5 – 2011-02-17T17:52:28.633

15

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

Posted 2011-02-17T17:36:40.207

Reputation: 151