I have opened several text files (a.txt, b.txt, c.txt, ...) in different sessions of vi launched from different instances of a bash shell. Having then accessed that machine remotely, I wish to determine which session of vi is associated with a particular text file (e.g., a.txt) and specifically close that session, preferably while saving the current contents of the buffer (as opposed to executing a process kill). How can these actions be performed?
Tell me more
×
Unix & Linux Stack Exchange is a question and answer site for
users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
|
|
||||
| show 4 more comments |
|
To see open files, use lsof(8). To control an existing instance of |
|||||||
|

file /proc/<pid>/fd/6This gives you the name of the swap fileviis using, which directly tells you which file it's operating on. It's rather hackish and it doesn't help you save buffer contents. I'm hoping aviguru can enlighten us on that matter. – Joseph R. Nov 26 '12 at 17:50/proc/<pid>/fd/folder contains the symlinks0,1,2, and4. The first three point to/dev/pts/3and the last one points to the swap file. Many thanks. – user001 Nov 26 '12 at 17:56fileon all the files in thefddirectory and parsing the output for a line containing ".swp" – Joseph R. Nov 26 '12 at 17:58printf ":wq\n" > /proc/<pid>/fd/0but no joy! ":wq" appears in theviwindow butvidoesn't seem to respond. – Joseph R. Nov 26 '12 at 18:10GNU screen. Specifically thestuffcommand can enter text as though it was typed. I expecttmuxhas similar features. – donothingsuccessfully Nov 26 '12 at 18:13