Vim – Editing Text File with Vim Does Not Update tail -f

filestailvim

I'm using tail -f a.txt to watch updates on a file called a.txt.

If I update the file using something like ls -a >> a.txt in a second virtual console, the changes will display in real-time in the first one.

If I update the file using Vim in a second virtual console, the changes will not display in the first one.

I don't necessarily expect it to trigger an update in that window – but why exactly doesn't this update the terminal running the tail -f command?

Best Answer

If you edit a file with vim, typically it reads the file into memory, then writes a new file. So tail is now operating on an out of date copy of the file (which remains in the file system until tail (and any other program) stops using it.

You can make tail follow the filename (rather than the file) by using:

tail -F yourfile  

Note the upper case F.

Related Question