Is there any way if we can know that what change was made to the file opened in vi before quitting?
As i opened a huge file made some changes yesterday and didnt save it.
Today when i was quitting the vi , i came to know that some changes are made(as i got warning with q option).I need to know what changes were made , so i can save it or discard it.
kailash19, what scrutinizers and jiliagres suggestions have in common is this:
As vi opens a file it creates a backup copy somewhere. Depending on the specific flavour of vi or vim you use it might be in different locations: the vi under AIX creates this file in /var/tmp, vim uses .<filename>.swp in the same directory as the file, etc.. Real vi's delete this backup copy upon leaving the editor, but some vi-clones (like vim) retain these files until explicitly configured to do otherwise.
By using the "diff" utility you can compare the text you have right now in your editing buffer (the file in the open editing session) and the contents of this backup copy of the original file and find out the differences. You can even write these differences to a file and open this in another editor window as vi is multi-windowed (see the ":e", ":n" and ":rew" commands in the man pages).
To clarify, I wasn't suggesting to use any backup file that vi itself possibly creates by itself but to save the current buffer in a temporary file and compare it to the original one. This can be done simply with the two commands I already posted:
:w /tmp/current
:!diff -c /tmp/current % | less
(replace less by more if less is missing).
The backup files created by the traditional vi in /var/tmp aren't usable for that task as not being a plain copy of the current file but a structured binary designed to allow file recovery should the editor crashed (vi -r). This applies also to vim .swp files which aren't either editable text files.