On 15-Mar-09 16:23, nlloyds wrote:
> In a script like this:
> 
> function! s:myfunction() range
>   echo a:firstline
>   echo a:lastline
>   echo line("'<")
>   echo line("'>")
> endfunction
> 
> command! -range myfunction :call s:myfunction()
> 
> When I run the command and try to get the start and end lines of the
> visual
> selected range, a:firstline and a:lastline always give me the line I
> was on
> when the command was executed. The '< and '> give me the lines of the
> range,
> but if I execute the command again with no visual selection they give
> me the
> visual range that was selected the last time.
> 
> I'd like to run a function on the whole file (%) if not in visual
> mode, or
> use the first and last selected lines to run it on a range if a visual
> block
> is selected. My script now uses getline(1, $) at one point, and I'd
> like to
> be able to replace those with the first and last selected lines if
> there is
> a selection.
> 
> What's the best way to do this? I'm using Vim 7.1 on Linux (though
> would
> like it to work on any platform with 7.1+)
> 
> Thanks,
> 
> Nathan

You need to explicitly pass the range from the command to the function via the 
<line1> and <line2> replacements:

command! -range Myfunction <line1>,<line2>call s:Myfunction()

-- regards, ingo

PS: Better post these kinds of questions to vim_use please.

-- 
   -- Ingo Karkat -- /^-- /^-- /^-- /^-- /^-- /^-- http://ingo-karkat.de/ --


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui