Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

First use Vim to edit a file, say /tmp/A.

Assuming that vim process is the only one that accesses /tmp/A, then use "ctrl+z" to suspend the process, and execute

fuser /tmp/A

Then you see nothing in the output.

However, if you use "less" to open that file, you could see the pid of less in the fuser output.

Is there anthing special about vim that makes this weird scenario?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Yes, vim does not open the file until it needs to save it. Instead, vim uses a temporary hidden swap file to save changes you make incrementally. Once you save the file (:w) it will write to the original file.

You can see that for yourself by using lsof, i.e.:

$ lsof -n -p `pidof vim`
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
[...]
vim     9695 gert    4u   REG  252,1    12288 410388 /tmp/.a.swp
[...]

This is common behaviour for editors. less just reads the file and it's of no benefit to use tricks when just opening a file for reading.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.