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

Determine the position we left off before moving to the command line

Expand Messages
  • Axel Bender
    I m searching a way to determine the last cursor position before entering the command line to execute a command defined with ... If I start from a visual
    Message 1 of 8 , Apr 14, 2013
    • 0 Attachment
      I'm searching a way to determine the last cursor position before entering the command line to execute a command defined with

      :command -range=% aaa call <line1>,<line2>func().

      If I start from a visual block, I'm able to retrieve that position with line(".") or a:firstline in func().

      However, if I don't use a range, e.g. if I just enter :aaa, I'm unable able to determine that position as line(".")/a:firstline are both 1.

      I tried to resort to defining the command like so

      :command -range=% aaa normal ma| <line1>,<line2>call ... | normal `a

      but to no avail; func() wouldn't get executed...

      Any tips?

      --
      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Ben Fritz
      ... I know of no reason whatsoever why line( . ) would not work. I use it all the time. Is your cursor actually on line 1 when you invoke the command? -- --
      Message 2 of 8 , Apr 15, 2013
      • 0 Attachment
        On Sunday, April 14, 2013 7:54:14 AM UTC-5, Axel Bender wrote:
        > I'm searching a way to determine the last cursor position before entering the command line to execute a command defined with
        >
        > :command -range=% aaa call <line1>,<line2>func().
        >
        > If I start from a visual block, I'm able to retrieve that position with line(".") or a:firstline in func().
        >
        > However, if I don't use a range, e.g. if I just enter :aaa, I'm unable able to determine that position as line(".")/a:firstline are both 1.
        >
        > I tried to resort to defining the command like so
        >
        > :command -range=% aaa normal ma| <line1>,<line2>call ... | normal `a
        >
        > but to no avail; func() wouldn't get executed...
        >
        > Any tips?

        I know of no reason whatsoever why line('.') would not work. I use it all the time. Is your cursor actually on line 1 when you invoke the command?

        --
        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • John Little
        ... That doesn t look right; don t you mean ... If you start from visual block , when you type the : vim puts ... on the command-line , and then you type the
        Message 3 of 8 , Apr 15, 2013
        • 0 Attachment
          On Monday, April 15, 2013 12:54:14 AM UTC+12, Axel Bender wrote:

          > :command -range=% aaa call <line1>,<line2>func().

          That doesn't look right; don't you mean

          :command! -range=% Aaa <line1>,<line2>call Func()

          If you "start from visual block", when you type the : vim puts

          :'<,'>

          on the "command-line", and then you type the command name

          :'<,'>Aaa

          if Func is defined with the range attribute, line(".") and a:firstline will be set to that of '<. If you remove the "'<,'>", you've just specified the whole file, so line(".") and a:firstline will be 1.

          You can still get at '< and '> in your function, they will be line("'<") and line("'>"), though that will give the last visual mode used, even if there's no visual mode when the command is invoked.

          HTH, John Little

          --
          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Axel Bender
          Hm, somehow my last (yesterday evening) post got removed... Anyway. I attached a VimL file which shows the problem (at least here: version 7.3.903, Windows 7,
          Message 4 of 8 , Apr 15, 2013
          • 0 Attachment
            Hm, somehow my last (yesterday evening) post got removed...

            Anyway. I attached a VimL file which shows the problem (at least here: version 7.3.903, Windows 7, 64 bit). Please try to execute :Hi w/o a visual block, the cursor being in line 2.

            --
            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Christian Brabandt
            ... That is because of the way, function-range is implemented. ,----[ :h :call ]- ... `---- Therefore I usually specify the firstline and lastline as parameter
            Message 5 of 8 , Apr 16, 2013
            • 0 Attachment
              On Tue, April 16, 2013 08:42, Axel Bender wrote:
              > Anyway. I attached a VimL file which shows the problem (at least here:
              > version 7.3.903, Windows 7, 64 bit). Please try to execute :Hi w/o a
              > visual block, the cursor being in line 2.
              >

              That is because of the way, function-range is implemented.

              ,----[ :h :call ]-
              | :[range]cal[l] {name}([arguments])
              | [匽
              | 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.
              `----

              Therefore I usually specify the firstline and lastline as parameter to
              the function (with range attribute) and just call the function using
              :call (without an address). This works around moving the cursor and
              executes the function just once. Within the function, I can work
              within the expected range.

              I think, this was sometimes also discussed on vim_dev but changing
              this behaviour would be a backwards incompatible change.

              regards,
              Christian

              --
              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Christian Brabandt
              ... it was discussed here: https://groups.google.com/d/msg/vim_dev/qs3RmTMMh44/40XgaSz9TbEJ regards, Christian -- -- You received this message from the
              Message 6 of 8 , Apr 16, 2013
              • 0 Attachment
                On Tue, April 16, 2013 09:07, Christian Brabandt wrote:
                > I think, this was sometimes also discussed on vim_dev but changing
                > this behaviour would be a backwards incompatible change.

                it was discussed here:
                https://groups.google.com/d/msg/vim_dev/qs3RmTMMh44/40XgaSz9TbEJ

                regards,
                Christian

                --
                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php

                ---
                You received this message because you are subscribed to the Google Groups "vim_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              • Axel Bender
                Thanks Christian, that did it! -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying
                Message 7 of 8 , Apr 16, 2013
                • 0 Attachment
                  Thanks Christian,

                  that did it!

                  --
                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php

                  ---
                  You received this message because you are subscribed to the Google Groups "vim_use" group.
                  To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                  For more options, visit https://groups.google.com/groups/opt_out.
                • Anthony Campbell
                  I have a lot of abbreviations to automatically correct tyiping errors (hte to the, etc.). It works well for whole words but it would be useful to have it for
                  Message 8 of 8 , Apr 16, 2013
                  • 0 Attachment
                    I have a lot of abbreviations to automatically correct tyiping errors
                    (hte to the, etc.). It works well for whole words but it would be useful
                    to have it for some teminations, e.g. to catch words ending in *lly
                    which I tend to type as *lhy.

                    I haven't been able to find such a thing with google. It's no big deal
                    but given that one can do practically anything in vim, I thought I'd
                    ask.


                    --
                    Anthony Campbell - ac@...
                    http://www.acampbell.org.uk
                    http://www.reviewbooks.org.uk
                    http://www.skepticviews.org.uk
                    http://www.acupuncturecourse.org.uk
                    http://www.smashwords.com/profile.view/acampbell
                    https://itunes.apple.com/ca/artist/anthony-campbell/id73235412





                    --
                    --
                    You received this message from the "vim_use" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php

                    ---
                    You received this message because you are subscribed to the Google Groups "vim_use" group.
                    To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                    For more options, visit https://groups.google.com/groups/opt_out.
                  Your message has been successfully submitted and would be delivered to recipients shortly.