How to get vim to list the PIDs of selected files that are presently being edited, avoiding recovery mode, and not list all the other files
Solution 1:
after switching my focus to just vim -r
, and
-
Knowing that vim will try to put the swap file into the same directory as the file it's editing ( thanks to @romainl for the pointer to
:help swap-file
) -
observing that
vim -r
reports on the files in the current directory first, -
observing that the file name associated with the swap file is reported before the process id of the vim process, and
-
observing that vim appends
(STILL RUNNING)
if it finds the active process -
I changed the current directory appropriately and ran this code after plugging in the name of the
file-to-search-for
perl -lne ' last if /^\s+In directory/; undef $f if /^\d+/; $f = $1 if /^\s+file name:\s+(.*)\s*$/; if ( $f =~ m#/file-to-search-for# && /^\s+ process ID:\s(\d+).*?STILL RUNNING/ ) { print $1; $pid //= $1; } END { exit !$pid; } '
The pid of the running vim process is printed, and the exit status is zero when the appropiate swap file is found, and non-zero if the file was not being edited