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

105506Re: Anyshortcut for going back to previous searches?

Expand Messages
  • Christian Brabandt
    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
      -~----------~----~----~----~------~----~------~--~---
    • Show all 8 messages in this topic