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

how to move to the next search match in next buffer/tab

Expand Messages
  • pixelterra
    Like everyone, I use / and ? all day long, and use n to go to the next match. Often, instead of starting again at the top of the page, I wish my n (or some
    Message 1 of 11 , Mar 10, 2010
    • 0 Attachment
      Like everyone, I use / and ? all day long, and use 'n' to go to the
      next match. Often, instead of starting again at the top of the page, I
      wish my 'n' (or some alternative) would go on to the next buffer/tab
      instead of the top of the page.

      Is there a setting or command for this? I've looked around and came up
      empty.

      --
      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
    • Ben Fritz
      ... No setting or option, but setting nowrapscan will prevent you from wrapping around to the top of the page, and then you can manually switch to the next
      Message 2 of 11 , Mar 10, 2010
      • 0 Attachment
        On Mar 10, 9:24 am, pixelterra <r...@...> wrote:
        > Like everyone, I use / and ? all day long, and use 'n' to go to the
        > next match. Often, instead of starting again at the top of the page, I
        > wish my 'n' (or some alternative) would go on to the next buffer/tab
        > instead of the top of the page.
        >
        > Is there a setting or command for this? I've looked around and came up
        > empty.

        No setting or option, but setting 'nowrapscan' will prevent you from
        wrapping around to the top of the page, and then you can manually
        switch to the next buffer, tab, or window, jump to the top with gg,
        and continue on your way with n.

        --
        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
      • pixelterra
        seems some variation of :vimgrep may work, but i found the docs cryptic. -- You received this message from the vim_use maillist. Do not top-post! Type your
        Message 3 of 11 , Mar 10, 2010
        • 0 Attachment
          seems some variation of :vimgrep may work, but i found the docs
          cryptic.

          --
          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
        • Gary Johnson
          ... I thought that a refinement of ... with nowrapscan set might work, but even that much didn t work for me. I just got the error messages Error detected
          Message 4 of 11 , Mar 10, 2010
          • 0 Attachment
            On 2010-03-10, pixelterra wrote:
            > seems some variation of :vimgrep may work, but i found the docs
            > cryptic.

            I thought that a refinement of

            :try | normal n | catch | n | endtry

            with 'nowrapscan' set might work, but even that much didn't work for
            me. I just got the error messages

            Error detected while processing :
            E385: search hit BOTTOM without match for: who

            and the 'catch' clause was never executed. I tinkered with it
            briefly and gave up. Maybe you or someone else can expand on that.

            Regards,
            Gary

            --
            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
          • Andy Wokula
            ... Some notes: - needs wrapscan off (:set nowrapscan) to switch buffers; should be behave as usual with wrapscan on - a count works ok - bug: ignores
            Message 5 of 11 , Mar 10, 2010
            • 0 Attachment
              Am 10.03.2010 17:01, schrieb Ben Fritz:
              > On Mar 10, 9:24 am, pixelterra<r...@...> wrote:
              >> Like everyone, I use / and ? all day long, and use 'n' to go to the
              >> next match. Often, instead of starting again at the top of the page, I
              >> wish my 'n' (or some alternative) would go on to the next buffer/tab
              >> instead of the top of the page.
              >>
              >> Is there a setting or command for this? I've looked around and came up
              >> empty.
              >
              > No setting or option, but setting 'nowrapscan' will prevent you from
              > wrapping around to the top of the page, and then you can manually
              > switch to the next buffer, tab, or window, jump to the top with gg,
              > and continue on your way with n.

              In a mapping:

              :nn <expr> n &ws \|\| search("","nW") ? "n" : ":bnext<CR>ggn"
              :nn <expr> N &ws \|\| search("","bnW") ? "N" : ":bprev<CR>G$N"

              Some notes:
              - needs 'wrapscan' off (:set nowrapscan) to switch buffers;
              should be behave as usual with 'wrapscan' on
              - a count works ok
              - bug: ignores that n can go backward, and N forward
              - maybe :<C-U>bnext is better than :bnext
              - maybe :hide bnext is preferred (if 'hidden' is not set); but maybe
              you will want to see the error message if the buffer has changes
              - problem with folds:
              search(@/) and n behave differently on closed folds; if the last two or
              more matches are in a closed fold, then search(@/) will find the 2nd
              match in that fold, but n will jump out of the fold. Solution would be
              to prepend the commands after the question mark with "zv" (open fold),
              but then a count no longer works -> some more effort is needed.
              - anyway: because we are in a mapping, n will no longer open folds
              (:h 'foldopen')
              - I only assume that search("") is equivalent to search(@/),
              maybe even a little faster, as a compiled pattern will be reused?
              it's another assumption ...
              - ... etc ...

              @Gary: a try block cannot catch Beeps from a Normal mode command.

              --
              Andy

              --
              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
            • Tim Chase
              ... did you try exec normal n instead of normal n which eats the rest of your line, and if mapping, using instead of | ? Just cleaning up your
              Message 6 of 11 , Mar 10, 2010
              • 0 Attachment
                Gary Johnson wrote:
                > On 2010-03-10, pixelterra wrote:
                >> seems some variation of :vimgrep may work, but i found the docs
                >> cryptic.
                >
                > I thought that a refinement of
                >
                > :try | normal n | catch | n | endtry
                >
                > with 'nowrapscan' set might work, but even that much didn't work for
                > me. I just got the error messages
                >
                > Error detected while processing :
                > E385: search hit BOTTOM without match for: who
                >
                > and the 'catch' clause was never executed.

                did you try

                exec 'normal n'

                instead of

                normal n

                which eats the rest of your line, and if mapping, using "<bar>"
                instead of "|"?

                Just cleaning up your example...I too got the uncatchable E385
                whether issued directly or <bar>'ed and issued as a mapping.
                However, if I wrapped it in a function, it seemed to work:

                function! SearchWrap()
                try
                normal n
                catch
                n
                endtry
                endfunction
                nnoremap <f4> :call SearchWrap()<cr>

                seemed to do the trick for me with 'nowrapscan' set. I'm not
                sure why the E385 refuses to be caught by an in-line (<bar>'ed)
                try/catch/endtry block. I even tried wrapping the "n" in an
                exec, in case it was choking on the bar as a parameter.

                Andy's reply just came in:

                > @Gary: a try block cannot catch Beeps from a Normal mode
                > command.

                but I'm not sure (1) where this is documented, and (2) why Gary
                and I were getting the E385 (an error, not just a beep) and it
                still wasn't being caught inline vs. in my function.

                Seeing Andy's solution, I like it better, but I'm still left
                scratching my head a bit on try/except issues.

                -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
              • Christian Brabandt
                ... I tried using vimgrep: fu! Files() let list=[] for id in range(1,bufnr( $ )) if buflisted(id) call add(list, fnamemodify(bufname(id), :p )) endif
                Message 7 of 11 , Mar 10, 2010
                • 0 Attachment
                  On Wed, March 10, 2010 6:16 pm, Andy Wokula wrote:
                  > In a mapping:
                  >
                  > :nn <expr> n &ws \|\| search("","nW") ? "n" : ":bnext<CR>ggn"
                  > :nn <expr> N &ws \|\| search("","bnW") ? "N" : ":bprev<CR>G$N"
                  >

                  I tried using vimgrep:

                  fu! <sid>Files()
                  let list=[]
                  for id in range(1,bufnr('$'))
                  if buflisted(id)
                  call add(list, fnamemodify(bufname(id), ':p'))
                  endif
                  endfor
                  return list
                  endfu

                  fu! <sid>Search()
                  let a=input('/')
                  if !empty(a)
                  return ':silent vimgrep /' . escape(a,'/') .'/gj ' .
                  join(<sid>Files()) . "\n:redraw!\n"
                  else
                  return ":redraw!\n"
                  endif
                  endfu

                  fu! <sid>MapKeys(mode)
                  if a:mode
                  cnoremap <expr> / <sid>Search()
                  noremap n :cn<CR>
                  noremap N :cp<CR>
                  else
                  cunmap /
                  unmap n
                  unmap N
                  endif
                  endfu

                  has some drawbacks too:
                  - does not work, if you need / within the search phrase
                  (at least I did not succeed checking if the cursor is
                  on the first char, getcmdpos() does not seem to work
                  in an expression mapping)
                  - does probably not search unnamed buffers
                  - ignores the fact, that n/N can switch direction
                  - does not search unlisted files
                  - probably some more ...

                  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
                • Gary Johnson
                  ... No. Duh. Thanks for pointing that out. ... Ditto. Regards, Gary -- You received this message from the vim_use maillist. Do not top-post! Type your
                  Message 8 of 11 , Mar 10, 2010
                  • 0 Attachment
                    On 2010-03-10, Tim Chase wrote:
                    > Gary Johnson wrote:
                    > >On 2010-03-10, pixelterra wrote:
                    > >>seems some variation of :vimgrep may work, but i found the docs
                    > >>cryptic.
                    > >
                    > >I thought that a refinement of
                    > >
                    > > :try | normal n | catch | n | endtry
                    > >
                    > >with 'nowrapscan' set might work, but even that much didn't work for
                    > >me. I just got the error messages
                    > >
                    > > Error detected while processing :
                    > > E385: search hit BOTTOM without match for: who
                    > >
                    > >and the 'catch' clause was never executed.
                    >
                    > did you try
                    >
                    > exec 'normal n'
                    >
                    > instead of
                    >
                    > normal n
                    >
                    > which eats the rest of your line, and if mapping, using "<bar>"
                    > instead of "|"?

                    No. Duh. Thanks for pointing that out.

                    > Andy's reply just came in:
                    >
                    > >@Gary: a try block cannot catch Beeps from a Normal mode
                    > >command.
                    >
                    > but I'm not sure (1) where this is documented, and (2) why Gary
                    > and I were getting the E385 (an error, not just a beep) and it
                    > still wasn't being caught inline vs. in my function.
                    >
                    > Seeing Andy's solution, I like it better, but I'm still left
                    > scratching my head a bit on try/except issues.

                    Ditto.

                    Regards,
                    Gary

                    --
                    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
                  • Andy Wokula
                    ... Again ... ... It was an error message, not a Beep, ok. ... -- Andy -- You received this message from the vim_use maillist. Do not top-post! Type your
                    Message 9 of 11 , Mar 10, 2010
                    • 0 Attachment
                      Am 10.03.2010 18:23, schrieb Tim Chase:
                      > Gary Johnson wrote:
                      >> I thought that a refinement of
                      >>
                      >> :try | normal n | catch | n | endtry
                      >>
                      >> with 'nowrapscan' set might work, but even that much didn't work for
                      >> me. I just got the error messages
                      >>
                      >> Error detected while processing :
                      >> E385: search hit BOTTOM without match for: who
                      >>
                      >> and the 'catch' clause was never executed.
                      >
                      > Just cleaning up your example...I too got the uncatchable E385 whether
                      > issued directly or <bar>'ed and issued as a mapping.

                      Again ...
                      :set nowrapscan

                      This works for me (typed at the cmdline):
                      :try| exec "normal! n"| catch| next| endtry

                      This does not work:
                      :nn n :try<bar>exec "normal! n"<bar> catch<bar> next<bar> endtry<CR>

                      But this works (surrounded with another :exec):
                      :nn n :exec "try<bar>exec 'normal! n'<bar> catch<bar> next<bar> endtry"<CR>

                      which I think is similar to:

                      > However, if I wrapped it in a function, it seemed to work:
                      >
                      > function! SearchWrap()
                      > try
                      > normal n
                      > catch
                      > n
                      > endtry
                      > endfunction
                      > nnoremap <f4> :call SearchWrap()<cr>

                      > seemed to do the trick for me with 'nowrapscan' set. I'm not sure why
                      > the E385 refuses to be caught by an in-line (<bar>'ed) try/catch/endtry
                      > block. I even tried wrapping the "n" in an exec, in case it was choking
                      > on the bar as a parameter.
                      >
                      > Andy's reply just came in:
                      >
                      >> @Gary: a try block cannot catch Beeps from a Normal mode
                      >> command.

                      It was an error message, not a Beep, ok.

                      > but I'm not sure (1) where this is documented, and (2) why Gary and I
                      > were getting the E385 (an error, not just a beep) and it still wasn't
                      > being caught inline vs. in my function.
                      >
                      > Seeing Andy's solution, I like it better, but I'm still left scratching
                      > my head a bit on try/except issues.
                      >
                      > -tim

                      I found this:

                      :h map_return
                      | Note that when an error is encountered (that causes an error message or beep)
                      | the rest of the mapping is not executed. This is Vi-compatible.

                      --
                      Andy

                      --
                      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
                    • Ben Fritz
                      ... For (1), it s at :help :bar -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are replying to.
                      Message 10 of 11 , Mar 10, 2010
                      • 0 Attachment
                        On Mar 10, 11:23 am, Tim Chase <v...@...> wrote:
                        > Andy's reply just came in:
                        >
                        > > @Gary: a try block cannot catch Beeps from a Normal mode
                        > > command.
                        >
                        > but I'm not sure (1) where this is documented, and (2) why Gary
                        > and I were getting the E385 (an error, not just a beep) and it
                        > still wasn't being caught inline vs. in my function.
                        >

                        For (1), it's at :help :bar

                        --
                        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
                      • Andy Wokula
                        ... -- Andy -- 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
                        Message 11 of 11 , Mar 10, 2010
                        • 0 Attachment
                          Am 10.03.2010 22:40, schrieb Ben Fritz:
                          >
                          >
                          > On Mar 10, 11:23 am, Tim Chase<v...@...> wrote:
                          >> Andy's reply just came in:
                          >>
                          >>> @Gary: a try block cannot catch Beeps from a Normal mode
                          >>> command.
                          >>
                          >> but I'm not sure (1) where this is documented, and (2) why Gary
                          >> and I were getting the E385 (an error, not just a beep) and it
                          >> still wasn't being caught inline vs. in my function.
                          >>
                          >
                          > For (1), it's at :help :bar

                          Yep, that makes things more clear:

                          | Note that when the command before the '|' generates an error, the following
                          | commands will not be executed.

                          --
                          Andy

                          --
                          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
                        Your message has been successfully submitted and would be delivered to recipients shortly.