How to open the last edited file
To open the last edited file in the current directory, use the combination of the ls, head and vi commands as shown below.
Open file 1 and make changes.
$ vim file1 Save and close the file. Now open file 2 and make changes.
$ vim file2 Save and close the file. Next, run the following command to open the last edited file:
$ vim `ls -t | head -1` Here, ls -t sorts the file based on the time of modification, showing the last edited file first. head 1 picks up this first file and opens it in the vim text editor.