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

Anyshortcut for going back to previous searches?

Expand Messages
  • googler
    Suppose I am editing/viewing a file and searching for different regular expressions in the file, for example, issuing commands / abcd , /efgh , /ijkl and
    Message 1 of 8 , Jul 1, 2009
      Suppose I am editing/viewing a file and searching for different
      regular expressions in the file, for example, issuing commands "/
      abcd", "/efgh", "/ijkl" and "/mnop". Since my last search was for
      "mnop", that's what I have highlighted currently. Now if I want to go
      back to the previous search or the one (or two) before that, what is
      the easiest way to do that? I do not want to type the whole search
      string again. Is there a shortcut? If not, does there exist any script
      that I can use to get this functionality?

      Thanks for any response on this.

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Christian Brabandt
      ... 2 possibilities: - When starting a new search using / use the up-arrow key to select any of the previous searches. - Use the command-line window (:h
      Message 2 of 8 , Jul 1, 2009
        On Wed, July 1, 2009 6:52 pm, googler wrote:
        >
        > Now if I want to go back to the previous search or the one (or two)
        > before that, what is the easiest way to do that? I do not want to type
        > the whole search string again. Is there a shortcut? If not, does there
        > exist any script that I can use to get this functionality?

        2 possibilities:

        - When starting a new search using / use the up-arrow key to select any of
        the previous searches.
        - Use the command-line window (:h cmdline-window) using q/ and select any
        of your last search history entries


        regards,
        Christian
        --
        :wq!


        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tim Chase
        ... After pressing / you should be able to use up/down (or control+P or control+N) to navigate the search history. You can also use q/ to pull up the
        Message 3 of 8 , Jul 1, 2009
          googler wrote:
          > Suppose I am editing/viewing a file and searching for different
          > regular expressions in the file, for example, issuing commands "/
          > abcd", "/efgh", "/ijkl" and "/mnop". Since my last search was for
          > "mnop", that's what I have highlighted currently. Now if I want to go
          > back to the previous search or the one (or two) before that, what is
          > the easiest way to do that? I do not want to type the whole search
          > string again. Is there a shortcut? If not, does there exist any script
          > that I can use to get this functionality?

          After pressing "/" you should be able to use up/down (or
          control+P or control+N) to navigate the search history.

          You can also use

          q/

          to pull up the command-history window for the search. This
          allows you to modify the query as if it was a vim buffer itself.

          You can read more at

          :help c_<up>
          :help cmdline-history
          :help q/

          It stores 'history' number of previous items (defaults to 20
          items), and assumes that your version of vim was built with
          +cmdline_hist (check the output of ":ver" to verify)

          -tim






          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_use" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Tony Mechelynck
          ... Actually, there are several ways to use search history; most of them apply also to command history if you replace / or ? by : - Plain history: Hit / or ?
          Message 4 of 8 , Jul 1, 2009
            On 01/07/09 18:52, googler wrote:
            >
            > Suppose I am editing/viewing a file and searching for different
            > regular expressions in the file, for example, issuing commands "/
            > abcd", "/efgh", "/ijkl" and "/mnop". Since my last search was for
            > "mnop", that's what I have highlighted currently. Now if I want to go
            > back to the previous search or the one (or two) before that, what is
            > the easiest way to do that? I do not want to type the whole search
            > string again. Is there a shortcut? If not, does there exist any script
            > that I can use to get this functionality?
            >
            > Thanks for any response on this.

            Actually, there are several ways to use search history; most of them
            apply also to command history if you replace / or ? by :

            - Plain history:
            Hit / or ? then <Up> for "next older" or <Down> for "next newer".

            - Autocomplete from history
            Hit / or ? then part of the pattern. Now <Up> and <Down> will only
            "remember" the patterns which correspond to what you just typed.

            - History window (with +cmdline_hist compiled-in)
            Hit q/ or q? -- Vim opens a full-width window at the bottom, with all
            the latest search patterns (the newest one at bottom). Hitting <Enter>
            on any line will search for that (after closing the history window). Or
            you can edit (without leaving the window) /then/ hit Enter, to search on
            something slightly different than what you searched before. Use (for
            instance) :q if you decide to close the window without searching.


            Best regards,
            Tony.
            --
            Paul's Law:
            In America, it's not how much an item costs, it's how much you
            save.

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_use" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • _sc_
            ... yet another method that everyone s been ignoring is to hit / followed by ctrl-F to open the search history window can t have too many choices now, can we
            Message 5 of 8 , Jul 1, 2009
              On Wednesday 01 July 2009 11:52 am, googler wrote:
              >
              > Suppose I am editing/viewing a file and searching for different
              > regular expressions in the file, for example, issuing commands "/
              > abcd", "/efgh", "/ijkl" and "/mnop". Since my last search was for
              > "mnop", that's what I have highlighted currently. Now if I want to go
              > back to the previous search or the one (or two) before that, what is
              > the easiest way to do that? I do not want to type the whole search
              > string again. Is there a shortcut? If not, does there exist any script
              > that I can use to get this functionality?

              yet another method that everyone's been ignoring is to hit '/'
              followed by ctrl-F to open the search history window

              can't have too many choices now, can we

              sc


              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_use" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            • googler
              ... Hi everybody, thanks for your replies. All this information will definitely be helpful. However, when I posted this question, what I was thinking was if
              Message 6 of 8 , Jul 1, 2009
                On Jul 1, 2:21 pm, _sc_ <tooth...@...> wrote:
                > On Wednesday 01 July 2009 11:52 am, googler wrote:
                >
                >
                >
                > > Suppose I am editing/viewing a file and searching for different
                > > regular expressions in the file, for example, issuing commands "/
                > > abcd", "/efgh", "/ijkl" and "/mnop". Since my last search was for
                > > "mnop", that's what I have highlighted currently. Now if I want to go
                > > back to the previous search or the one (or two) before that, what is
                > > the easiest way to do that? I do not want to type the whole search
                > > string again. Is there a shortcut? If not, does there exist any script
                > > that I can use to get this functionality?
                >
                > yet another method that everyone's been ignoring is to hit '/'
                > followed by ctrl-F to open the search history window
                >
                > can't have too many choices now, can we
                >
                > sc

                Hi everybody, thanks for your replies. All this information will
                definitely be helpful. However, when I posted this question, what I
                was thinking was if there is a keystroke or two that will take me to
                the previous search or the one before that. Something like pressing
                CTRL key or a function key. Seems like there is no such shortcut. So
                was thinking if one can create such a mapping.

                Say I'm only interested in the last two searches - pressing F4 will
                take me to the previous search and F5 to the one before that. How can
                I create such a mapping? I checked a little bit and saw that vim saves
                only the last search string in a register ("/) and not the ones
                before. So when I perform a new search through / or ? , I should save
                my "/ content in another register to be used by F4 and F5. Is that how
                it should be done?

                --~--~---------~--~----~------------~-------~--~----~
                You received this message from the "vim_use" maillist.
                For more information, visit http://www.vim.org/maillist.php
                -~----------~----~----~----~------~----~------~--~---
              • Ben Fritz
                ... Simply use :nmap or :nnoremap with any of the methods already discussed. For example, these are basically equivalent and do ALMOST what you ...
                Message 7 of 8 , Jul 1, 2009
                  On Jul 1, 2:34 pm, googler <pinaki_...@...> wrote:
                  > Hi everybody, thanks for your replies. All this information will
                  > definitely be helpful. However, when I posted this question, what I
                  > was thinking was if there is a keystroke or two that will take me to
                  > the previous search or the one before that. Something like pressing
                  > CTRL key or a function key. Seems like there is no such shortcut. So
                  > was thinking if one can create such a mapping.
                  >

                  Simply use :nmap or :nnoremap with any of the methods already
                  discussed.

                  For example, these are basically equivalent and do ALMOST what you
                  want:

                  :nmap <F4> /<Up><Up><CR>
                  :nmap <F4> q/kk<CR>
                  --~--~---------~--~----~------------~-------~--~----~
                  You received this message from the "vim_use" maillist.
                  For more information, visit http://www.vim.org/maillist.php
                  -~----------~----~----~----~------~----~------~--~---
                • Christian Brabandt
                  Hi googler! ... ,---- ... `---- regards, Christian -- ... --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_use
                  Message 8 of 8 , Jul 1, 2009
                    Hi googler!

                    On Mi, 01 Jul 2009, googler wrote:

                    > Hi everybody, thanks for your replies. All this information will
                    > definitely be helpful. However, when I posted this question, what I
                    > was thinking was if there is a keystroke or two that will take me to
                    > the previous search or the one before that. Something like pressing
                    > CTRL key or a function key. Seems like there is no such shortcut. So
                    > was thinking if one can create such a mapping.
                    >
                    > Say I'm only interested in the last two searches - pressing F4 will
                    > take me to the previous search and F5 to the one before that. How can
                    > I create such a mapping? I checked a little bit and saw that vim saves
                    > only the last search string in a register ("/) and not the ones
                    > before. So when I perform a new search through / or ? , I should save
                    > my "/ content in another register to be used by F4 and F5. Is that how
                    > it should be done?

                    ,----
                    | fu! PrevSearch(...)
                    | let mode = exists("a:1") ? a:1 : 0
                    | let inc = exists("a:2") || 0
                    | let arg = (inc ? -1 : 1)
                    |
                    | let g:prev_search = exists("g:prev_search") ? g:prev_search + arg : 1
                    | let g:prev_search = (g:prev_search > (&history)) ? &history : ( g:prev_search < 1 ? 1 : g:prev_search )
                    | if mode
                    | return "\<C-U>" . histget("search", g:prev_search * -1)
                    | else
                    | return '/' . histget("search", g:prev_search * -1)
                    | endfu
                    |
                    | nnoremap <expr> <F5> PrevSearch()
                    | cnoremap <expr> <F5> PrevSearch(1)
                    | nnoremap <expr> <F6> PrevSearch(0,1)
                    | cnoremap <expr> <F6> PrevSearch(1,1)
                    `----


                    regards,
                    Christian
                    --
                    :wq!

                    --~--~---------~--~----~------------~-------~--~----~
                    You received this message from the "vim_use" maillist.
                    For more information, visit http://www.vim.org/maillist.php
                    -~----------~----~----~----~------~----~------~--~---
                  Your message has been successfully submitted and would be delivered to recipients shortly.