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

Re: Anyshortcut for going back to previous searches?

Expand Messages
  • 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 1 of 8 , Jul 1, 2009
    • 0 Attachment
      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 2 of 8 , Jul 1, 2009
      • 0 Attachment
        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 3 of 8 , Jul 1, 2009
        • 0 Attachment
          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 4 of 8 , Jul 1, 2009
          • 0 Attachment
            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 5 of 8 , Jul 1, 2009
            • 0 Attachment
              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.