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 <S-F4> :call PrependComment("up")<cr>
nmap <F4> :call PrependComment("down")<cr>
imap <S-F4> <esc>:call PrependComment("up")<cr>
imap <F4> <esc>:call PrependComment("down")<cr>

"" <F16> is <C-F4> (for me)
nmap <F16> :call PrependComment("stationary")<cr>
imap <F16> <esc>:call PrependComment("stationary")<cr>
vmap <F4> :call PrependComment("stationary_vmap")<cr>

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to