You created a new file which tail is not monitoring. Instead open two terminals in the same directory. run:
touch testfile
tail -f testfile
Now in the second terminal, run "ls >>testfile.
When a program opens a file, it gets a file descriptor back, which is an integer. This file descriptor is used for further reads and writes.
When you saved the file you loaded in vim, you created a new file with a new inode. The tail command still has the original file open. It won't be closed until you quit "tail -f" by pressing CTRL-C. After doing that, the kernel will delete the file.
Code:
touch testfile2
jschiwal@netcow:~/Download> ls -li testfile2
5963813 -rw-r--r-- 1 jschiwal jschiwal 0 2009-12-11 01:05 testfile2
jschiwal@netcow:~/Download> tail -f testfile2
vim testfile2
jschiwal@netcow:~/Download> ls -li testfile2
5963815 -rw-r--r-- 1 jschiwal jschiwal 28 2009-12-11 01:05 testfile2
ps -C tail
PID TTY TIME CMD
19111 pts/3 00:00:00 tail
jschiwal@netcow:~/Download> ls -l /proc/19111/fd/
total 0
lrwx------ 1 jschiwal jschiwal 64 2009-12-11 01:08 0 -> /dev/pts/3
lrwx------ 1 jschiwal jschiwal 64 2009-12-11 01:08 1 -> /dev/pts/3
lrwx------ 1 jschiwal jschiwal 64 2009-12-11 01:07 2 -> /dev/pts/3
lr-x------ 1 jschiwal jschiwal 64 2009-12-11 01:08 3 -> /home/jschiwal/Download/testfile2~ (deleted)
jschiwal@netcow:~/Download> lsof +L1
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME
amarok 13605 jschiwal 15u REG 8,6 0 0 770202 /tmp/ibAniGv6 (deleted)
amarok 13605 jschiwal 16u REG 8,6 0 0 770205 /tmp/ibHBfmQS (deleted)
amarok 13605 jschiwal 17u REG 8,6 0 0 770210 /tmp/iboYw2aF (deleted)
amarok 13605 jschiwal 18u REG 8,6 0 0 770211 /tmp/ibEJsPxr (deleted)
amarok 13605 jschiwal 22u REG 8,6 0 0 770212 /tmp/ib8sR5ce (deleted)
kio_file 18035 jschiwal txt REG 8,6 48648 0 1803959 /usr/bin/kdeinit4 (deleted)
tail 19111 jschiwal 3r REG 8,7 0 0 5963813 /home/jschiwal/Download/testfile2~ (deleted)
...
As you can see, it is common for programs to create temporary files, delete them, but continue to use the file descriptors to write to them. If the program crashes, the temporary file will be removed by the kernel automatically. It also solves the problem if the psuedo random filename of another program's temporary file happens to have the same name. It doesn't matter, the program won't be blocked from creating a new file.