Hi,
I'm a noob myself but I believe "VIM::Buffer.current.line" + a "vmap"
is all you need.
Here's what I've coded recently, maybe that'll help you out:
###
start of vimscript#
###
autocmd bufenter * :call Get_filetype()
nmap :call PrependComment("up")
nmap :call PrependComment("down")
imap :call PrependComment("up")
imap :call PrependComment("down")
"" is (for me)
nmap :call PrependComment("stationary")
imap :call PrependComment("stationary")
vmap :call PrependComment("stationary_vmap")
fun! Get_filetype()
ruby << EOF_Get_filetype
filetype = VIM::evaluate("&filetype")
$comment_token = case filetype
when "sh", "perl", "python", "ruby": "#"
when "c", "cpp", "java": "//"
when "vim": '"'
else ""
end
EOF_Get_filetype
endfun
fun! PrependComment(direction)
ruby << EOF_PrependComment
direction = VIM::evaluate("a:direction")
if direction == 'up'
VIM.command("normal -")
end
line = VIM::Buffer.current.line
if line =~ /^\s*#{$comment_token}[ [:alnum:]].*/ #
if comment at beginning of line
line.gsub!(/(^\s*)(#{$comment_token}[ ]?)(.*)/, '\1\3') #
delete comment
else
if direction == "stationary_vmap"
line.gsub!(/.+/, "#{$comment_token} \\0") #
comment token on the far left
else
line.gsub!(/[^ ].*/, "#{$comment_token} \\0") #
otherwise add comment
end
end
VIM::Buffer.current.line = line
if direction == 'down'
VIM.command("normal +")
end
EOF_PrependComment
endfun
#
end of vimscript#
#
If that's of any interest, I can send you the rest of the file if you
wish.
All the best and good luck,
Ben
On Mar 25, 10:24 am, anton.hornqu...@gmail.com wrote:
> Hi,
>
> I've checked the docs on the ruby scripting features in vim but I
> cannot find a way to retrieve the visual selection area in either
> VIM::window or VIM::buffer. Is there any way to do this or any easy
> workaround for this?
>
> As an example I would like to be able to visually select an area and
> invoke a ruby script that would add a comment line to the top and
> bottom of the selection (while of course preserving undo history).
> Also I would like to be able to select an arbitrary area and execute a
> ruby script that could search in for certain characters in the area.
>
> /Anton
--~--~-~--~~~---~--~~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---