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

Re: How to make search with 'wrapscan' more convenient?

Expand Messages
  • Marcin Szamotulski
    ... You can write your own function which can use searchpos() function, setting mark with :normal mmgg (or even better remember the position in a global (g:)
    Message 1 of 6 , Jan 30, 2013
    • 0 Attachment
      On 03:21 Wed 30 Jan , Wiktor Ruben wrote:
      > Hello,
      >
      > I have 'set wrapscan' in my .vimrc. During search Vim displays 'search
      > hit bottom, continuing at top' message. It is pretty useless with
      > 'wrapscan' because in most cases what I'm really interested in, is
      > notification whether I have reached position from which my search
      > started.
      >
      > Example: I have file with 1000 lines of text. I start '/foo' at line
      > 400. I want to search whole file i.e. lines 400 - 1000 and 1 - 400.
      > Then I want Vim to notify me "search hit starting position". Is there
      > a way to make Vim to behave like this?
      >
      > Without such notification I end up racking my brain: "Hmm, have I
      > already reached line 400?" every 'n' pressing after 'search hit
      > bottom, continuing at top' message. I often miss starting position and
      > after couple of redundant 'n' find myself doing search through text
      > that has been already searched.
      >
      > My current workflow is to set 'nowrapscan', then mark my current
      > position with 'mm', then 'gg' and doing 'n' until Vim displays 'search
      > hit bottom, without match for foo'. Then I do '`m' to get back where I
      > were before search. How can I improve 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.
      >

      You can write your own function which can use searchpos() function,
      setting mark with ':normal mmgg' (or even better remember the position in
      a global (g:) variable. You can set the nowrapscan flag on the search()
      function and only thet if the position is beyond (for forward search) if
      it already hit bottom. Finally, you can write a command which invokes
      the function. If you use <q-args> you will type a pattern in exactly
      the same way as you type it in the command line. The last step would be
      to makes maps n and N which invokes the search, but in such a way that
      it uses the starting position set by the first search. I guess this
      difficulty is the reason why vim behaves like it behaves. How you could
      now using n/N that the search is a new search.

      AFAIK vim has no option for that.

      Happy Vimming,
      Marin


      --
      --
      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.
    • Tim Chase
      On Wed, 30 Jan 2013 03:21:11 -0800 (PST) Wiktor Ruben ... While I ve experienced the same want for a wrapscan from where my search started sort of option,
      Message 2 of 6 , Jan 30, 2013
      • 0 Attachment
        On Wed, 30 Jan 2013 03:21:11 -0800 (PST) Wiktor Ruben
        <smieciarski@...> wrote:
        > My current workflow is to set 'nowrapscan', then mark my current
        > position with 'mm', then 'gg' and doing 'n' until Vim displays
        > 'search hit bottom, without match for foo'. Then I do '`m' to get
        > back where I were before search. How can I improve it?

        While I've experienced the same want for a "wrapscan from where my
        search started" sort of option, and I don't have a good solution, in
        such cases I sometimes use either

        :g/pattern

        or

        :g/pattern/#

        to either just print the matches, or number them (which then usually
        leads to a jump to the line in question with something like 314G).

        You can modify the command to print a range of lines if needed:

        :g/pattern/-5;+5#

        or

        :g/pattern/?{?,/}/#

        to give some context.

        So, while not a perfect answer, it works for most of my use cases.

        -tim


        --
        --
        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.
      • Bee
        ... Where is that documented? Bill -- -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are
        Message 3 of 6 , Jan 30, 2013
        • 0 Attachment
          On Jan 30, 11:00 am, Tim Chase <v...@...> wrote:
          >   :g/pattern/#
          >
          > number them (which then usually
          > leads to a jump to the line in question with something like 314G).

          Where is that documented?

          Bill

          --
          --
          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.
        • Tim Chase
          On Wed, 30 Jan 2013 20:05:06 -0800 (PST) Bee ... It s a combination of ... -tim -- -- You received this message from the vim_use
          Message 4 of 6 , Jan 31, 2013
          • 0 Attachment
            On Wed, 30 Jan 2013 20:05:06 -0800 (PST) Bee <forth@...>
            wrote:

            > On Jan 30, 11:00 am, Tim Chase <v...@...> wrote:
            > >   :g/pattern/#
            > >
            > > number them (which then usually
            > > leads to a jump to the line in question with something like 314G).
            >
            > Where is that documented?

            It's a combination of

            :help :g

            with the "#" ex command:

            :help :#

            -tim


            --
            --
            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.
          • Bee
            ... Ah, thank you... I tried ... Forgot about using : for commands. Bill -- -- You received this message from the vim_use maillist. Do not top-post! Type
            Message 5 of 6 , Jan 31, 2013
            • 0 Attachment
              On Jan 31, 3:42 am, Tim Chase <v...@...> wrote:
              > On Wed, 30 Jan 2013 20:05:06 -0800 (PST) Bee <fo...@...>
              > wrote:
              >
              > > On Jan 30, 11:00 am, Tim Chase <v...@...> wrote:
              > > >   :g/pattern/#
              >
              > > > number them (which then usually
              > > > leads to a jump to the line in question with something like 314G).
              >
              > > Where is that documented?
              >
              > It's a combination of
              >
              >   :help :g
              >
              > with the "#" ex command:
              >
              >   :help :#
              >
              > -tim

              Ah, thank you...
              I tried
              :help #

              Forgot about using : for commands.

              Bill

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