Thanks so....much for your work! The solution (of course) was much more
elegant than I thought it could be. I am glad I posted it for consideration
first...

Steve Tuckner

-----Original Message-----
From: Ned Konz [mailto:ned / bike-nomad.com]
Sent: Friday, July 05, 2002 6:49 PM
To: ruby-talk / ruby-lang.org
Subject: Ruby extensions for VIM


OK, here's a file that you can put in your ~/.vim/plugin directory
that will extend Vim's Ruby model to allow sort, each, etc.
as well as whole buffer replacements like:

ruby $curbuf.set_to( $curbuf.sort )
ruby $curbuf.set_to( $curbuf.grep(/abc/))

" Extension to built-in Ruby support to add enumerable (each, sort,
etc.) to
" both VIM::Buffer (class & instance) and VIM::Window (class)
if has("ruby")
ruby <<EOF
module VIM
  class Buffer
   include Enumerable
   # each line in buffer...
   def each(&block)
     (1..count).each { |n| block.call(self[n]) }
   end
   def each_with_index(&block)
     (1..count).each { |n| block.call(self[n],n) }
   end
   # set me to the given array of strings
   # so you can do (for instance):
   # ruby $curbuf.set_to( $curbuf.sort )
   # ruby $curbuf.set_to( $curbuf.grep(/abc/))
   def set_to(arr)
     if arr.size <= count
       arr.each_with_index { |s,i| self[i+1] = s }
       while count > arr.size
         self.delete(count)
       end
     else
       arr.each_with_index do |s,i|
         if i+1 <= count
           self[i+1] = s
         else
           append(i, s)
         end
       end
     end
   end
   # each buffer...
   def self.each(&block)
     (0..count-1).each { |n| block.call(self[n]) }
   end
  end
  class Window
   include Enumerable
   # each window...
   def self.each(&block)
     (0..count-1).each { |n| block.call(self[n]) }
   end
 end
end
EOF
endif