Here's a little script I cooked up manage opening all the files in a given project in one gVim session at once.

This script will scan the current directory and any subdirectories for files with matching extensions, and then send the lot to gVim for editing.

Invoke the script with a list of extensions to open. For example:

vitree.pl pl pm t
is a nice way to open the files in a perl project.

The script is win32 only. So if you are working on a real computer, you'll have to switch the create process call to 'system'.

# ViTree use warnings; use strict; use File::Find; use Win32::Process; use Time::HiRes qw(sleep); # get set of extensions to work with. my %extensions; @extensions{ @ARGV } = (); # Come up with a more or less unique gVim server name. my $seed = int( rand 1000 ); my $servername = GetServerName( $seed ); # Build a list of files to open. my @files; find( \&MatchFiles, '.' ); exit unless @files; # and open them. my $counter = 0; print "Opening files:\n"; foreach my $file ( @files ) { print "$counter\t$file\n"; my $ProcessObj; # I was using system(1,blah blah) but that maxed out at 64 files. # Process::Create seems to handle anything I throw at it. Win32::Process::Create( $ProcessObj, "C:/WINDOWS/gvim.BAT", qq(gvim --servername $servername --remote-silent "$file"), 0, NORMAL_PRIORITY_CLASS, "." ) || die ErrorReport(); # Waiting for a bit keeps files from disappearing. # Also prevents "Application failed to initialize" errors. if ( $counter++ ) { sleep(0.1); } else { # need to wait longer at the first invocation # otherwise we sometimes miss a file or two. sleep(1); } } # the "wanted" function for File::Find sub MatchFiles { no warnings 'uninitialized'; /\.(\w*)$/; my $ext = $1; return unless length $ext; push @files, $File::Find::name if exists $extensions{$ext}; } # I broke this out earlier when # I thought I needed to spawn # multiple gVim servers to work # around a limit in gVim. # # The problem is with windows, and # the work around is different, but # I never put this back. Damn lazy. sub GetServerName { my $seed = shift; my $time = time; return "$seed-$time"; } # Copied straight from the Win32::Process docs. sub ErrorReport { print Win32::FormatMessage( Win32::GetLastError() ); }


TGI says moo


In reply to Open matching files in gVim by TGI

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.