How do I add a log file path to a vi file to monitor all the changes made to the file?

I'm curious to know how do I add an empty log file (test1.log) to an existing text file to monitor all the changes made to a.txt.
Is this expression

export PATH=$PATH:/home/test1.log

right to be added to the text file a.txt?

Exporting in the environment variable PATH a file name is searching for trouble...

It is unclear to me what you are wanting to achieve, usually you add/use a log file to trace what a program is doing or not... what you seem to be after is more like a history of a file...

What are you actually planning to log in vi?

Every keystroke while in the editor?

Are you looking for a keystroke logging application?

If so, you might consider logkeys :

GitHub - kernc/logkeys: A GNU/Linux keylogger that works!

I think the functionality you are looking for is provided by vim, not by vi :slight_smile: - it would give you the lines where the changes occurred if thats what you are after?

:set nomore
:redir > c.txt
:changes
:redir END
:set more
:e c.txt

Like the script file...where sometimes it encounters error when executing and so the errors are reported to a log file.... My question is how do I add the directory of the log file to a script file?

you could just configure a logfile within your script.

LOGFILE=/whatever/you/want/logfile

Alternatively you just run the script with logfile options. For example:
To put output in logfile:

script > logfile

To put output and errors in logfile:

script 2>&1 > logfile

To separate:

script 1> logouput 2> logerror