tags:

views:

220

answers:

4

My question is similar to this how to monitor a text file in realtime but I want to do it in vim. I know I can read an opened file use tail -f sample.xml file, and when new content is written to the file, it'll also write the new content to my screen. Can I have vim automatically fill the new data when a file is updated?

+2  A: 

Don't know about automatically, but you can type:

:e!

to reload the file

dimba
Although this approach does not auto update the content, it does display the updated content. Thanks for your answer!
Patrick
A: 

Tail Bundle should do what you want. Note, haven't used it myself.

Alok
This is exactly feature I'm looking for, I'll give it a try later. Thanks for the hint!
Patrick
+1  A: 

VIM will warn you when a file has been updated so that you don't overwrite changes that have been made since you opened it. It will prompt you at that point to reload the file.

prestomation
Thanks for your answer, but vim did not warn me when the file was changed in my system :(
Patrick
+4  A: 

You can :set autoread so that vim reads the file when it changes. However (depending on your platform), you have to give it focus.

From the help:

When a file has been detected to have been changed outside of Vim and it has not been changed inside of Vim, automatically read it again. When the file has been deleted this is not done.

Peter
Thanks for the hint! This looks pretty promising, but it doesn't work on my system :( I'm using Mac10.6.2 iTerm with vim version 7.2.303 compiled with MacVim. Any additional comment I can try?
Patrick
erm, that's pretty weird. are you using the macvim gui or the terminal version? it works for me with macvim gui downloaded precompiled. (I do have to click on the app to give it focus though, as I mentioned.)
Peter
I was testing in terminal, after I used gvim (MacVim GUI) the function began to work! As you mentioned though, I need to focus gvim to update the content. Do you have any trick to update it even without focusing? Thanks for your help again.
Patrick
I don't know a solution to that, unfortunately. I'd be stunned if vim could do it without the change of focus - it would require vim to poll the filesystem to see when it changes. I think you'd need a plugin for that.
Peter