On Mon, 14 Mar 2011 09:01:03 -0700, mkorfmann wrote:

> Hey,
> 
> how can I access the current selected text within the :rubydo command?
> The current line is accessible by the $_ global variable, but I was not
> able to find such a variable for the current visual selection.

I've done this with VIM.evaluate("@*")

To overwrite the selection with the contents of the variable new_text, 
I've done:

old_x=VIM.evaluate("@x")
VIM::evaluate("setreg('x',\"#{new_text.vim_escape}\")")
VIM::command(":normal vgv\"xP")
VIM::evaluate("setreg('x',\"#{old_x.vim_escape}\")")

Where vim_escape is defined as follows:

   class String
      #escapes a string so it can be concatenated into
      #a call to VIM.evaluate
      def vim_escape
         result=dup
         result.gsub!("\\",'\\\\\\\\')
         result.gsub!('"','\"')
         result
      end
   end



-- 
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to