Loading ...
Sorry, an error occurred while loading the content.
 

Re: vimscript question

Expand Messages
  • Antoine J. Mechelynck
    ... yes, see :help :call : Without a range and for functions that accept a range, the function is called once. When a range is given the cursor is positioned
    Message 1 of 6 , Feb 1, 2005
      vim@... wrote:
      > Thanks Gary and Antoine for the replies. I have integrated Gary's
      > screen and cursor save/restore code into my function. Now if I call the
      > function using a call like
      > :10,20call CM("text")
      > or as a command like this:
      > :10,20CM text
      >
      > The cursor ends up on the line that begins the search range, in this
      > case line 10. Could it be that vim is positioning the cursor prior to
      > calling my function so my code thinks the start range is the current
      > cursor position?
      >
      > Thanks again,
      > Wayne
      >
      yes, see ":help :call":

      Without a range and for functions that accept a range, the
      function is called once. When a range is given the cursor is
      positioned at the start of the first line before executing the
      function.

      Best regards,
      Tony.
    • Gary Johnson
      ... That would be my guess. In fact, :help :call (just above :help function-range-example ) says: Without a range and for functions that accept a range,
      Message 2 of 6 , Feb 1, 2005
        On 2005-02-01, vim@... wrote:
        > Thanks Gary and Antoine for the replies. I have integrated Gary's
        > screen and cursor save/restore code into my function. Now if I call the
        > function using a call like
        > :10,20call CM("text")
        > or as a command like this:
        > :10,20CM text
        >
        > The cursor ends up on the line that begins the search range, in this
        > case line 10. Could it be that vim is positioning the cursor prior to
        > calling my function so my code thinks the start range is the current
        > cursor position?

        That would be my guess. In fact, ":help :call" (just above ":help
        function-range-example") says:

        Without a range and for functions that accept a range, the
        function is called once. When a range is given the cursor is
        positioned at the start of the first line before executing the
        function.

        You might try another approach. How about defining your CM command
        to take a range and then passing that range explicitly to your
        function. Then define the function _without_ the range argument,
        but something like this:

        function CM(pattern, firstline, lastline)

        Gary

        --
        Gary Johnson | Agilent Technologies
        garyjohn@... | Wireless Division
        | Spokane, Washington, USA
      Your message has been successfully submitted and would be delivered to recipients shortly.