Find all files currently open in Vim and/or gVim

vim -r 2>&1 | grep '\.sw.' -A 5 | grep 'still running' -B 5
Catches .swp, .swo, .swn, etc. If you have access to lsof, it'll give you more compressed output and show you the associated terminals (e.g., pts/5, which you could then use 'w' to figure out where it's originating from): lsof | grep '\.sw.$' If you have swp files turned off, you can do something like: ps x | grep '[g,v]im', but it won't tell you about files open in buffers, via :e [file].
Sample Output
1.    README.txt.swp
          owned by: rkulla   dated: Sat Apr 17 11:43:43 2010
         file name: ~rkulla/checkouts/projects/imgv/trunk/README.txt
          modified: no
         user name: rkulla   host name: blackbird
        process ID: 10104 (still running)
2.    filesum.swp
          owned by: rkulla   dated: Fri Apr 16 01:50:49 2010
         file name: ~rkulla/bin/filesum
          modified: no
         user name: rkulla   host name: blackbird
        process ID: 10669 (still running)
3.    reports.php.swp
          owned by: rkulla   dated: Thu Apr  8 22:15:45 2010
         file name: ~rkulla/Dropbox/mine/code/samples/reports.php
          modified: no
         user name: rkulla   host name: blackbird
        process ID: 10104 (still running)

3
By: rkulla
2010-04-17 19:43:35

These Might Interest You

What Others Think

- Prefer the command in your description: lsof | grep '\.sw.$' Useful for "undeleting" files.
zlemini · 426 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: