Reference to visual selection in :rubydo

37 views
Skip to first unread message

mkorfmann

unread,
Mar 14, 2011, 12:01:03 PM3/14/11
to vim_use
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.

Many thanks,
mkorfmann

Ken Bloom

unread,
Mar 15, 2011, 12:23:40 PM3/15/11
to vim...@googlegroups.com

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/

Manuel Korfmann

unread,
Mar 15, 2011, 1:22:40 PM3/15/11
to vim...@googlegroups.com
Thank you, any help with vimscript is highly appreciated . Today I wasted 2 hours, figuring out why I couldn't access a function's parameter :) . 
Do you know a good tutorial, which walks you through the editor api ? Probably discussing things like how one can replace text or how one can get the character under the cursor ?

Many thanks .

Reply all
Reply to author
Forward
0 new messages