Executing GVIM From Within A Live Script

Hey all,
I work in a group environment where multiple people may end up editing the same file. We have measures in place so no two people can edit the same file at once. I have a script that does the following:

call: script file

The script will backup the file,
Moves the file to a safe/busy name, ie: file_in_use (this lets other users know it's busy)
Calls vi to edit it,
I edit the file, then exit vi,
When I exit vi, the script then continues, by
Moving the edited file back to its original name, and
the script exits.

It looks like this bare bones example:

#protect original file
backup file to archive/bak_file_date
#create alternate file to edit.
mv file file_in_use
#edit the alt file
vi file_in_use
#after exiting vi, rename file to original name
mv file_in_use file
exit

This works brilliantly with vi. But in trying to engage gvim (vim) from within the script, gvim lets the script run its course and exit, then gvim edits "file_in_use," or, effectively, a new file named file_in_use.

When I call vi, it seems to stop or hold up the script until it's done with it, then the script continues with the subsequent steps.

I do not understand how to get gvim to act the same way as vi does.
Or can it?

Thanks in advance.
-Bruce

Why you would want to use anything instead of vi eludes me. ;-))

I suppose it is because gvim - graphically challenged vi-lookalike - detaches itself from the shell it is run in. Therefore the script continues to run instead of stopping until gvim exits. Use the -nofork option to prevent that.

I hope this helps.

bakunin

1 Like

I'm slowly coming around to the 'dark side!' GVIM is a great way to get one used to dabbling in vi. (I have been lured away from EMACS because of GVIM... so I'm hoping to get some credit! LOL.)