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

Re: Searching in another (split) window

Expand Messages
  • V.Chandrasekaran
    Hi Dave, I tried this. This works great. Thanks a lot. However, I am trying to refine it a little bit to suit the exact purpose I am looking for it. Basically
    Message 1 of 7 , Oct 2, 2004
    • 0 Attachment
      Hi Dave,
      I tried this. This works great. Thanks a lot. However, I am trying to
      refine it a little
      bit to suit the exact purpose I am looking for it. Basically I will keep
      "wincmd w" as it
      is, instead of changing to "split". But I want to somehow do the following
      sequence:

      * get the current line number of the cursor in the primary window. I could
      do this
      by 'let l=line(".")' in the current window
      * Then, switch to the other window
      * Set the cursor at the line number determined by $l as obtained by the
      "let" above.
      * Then, execute "normal n"

      I am stuck at the fourth step above. I am unable to find a function that
      will take the cursor
      to the line number specified by a user-defined variable. Any idea?

      ps: The problem with using 'split' for me is that I don't want to close the
      new window
      when I am done with the search. Because I may have some more searches to do
      in the
      same fashion. If I don't close the new window, the next invocation of the
      command will
      open yet another window finally filling with lots of windows.

      Thanks,
      chandra.

      ----- Original Message -----
      From: "Dave Silvia" <dsilvia@...>
      To: "Chandrasekaran V." <chandrasekaran_v@...>; <vim@...>
      Sent: Friday, October 01, 2004 6:13 PM
      Subject: RE: Searching in another (split) window


      > This is rather rudimentary, but it works. Feel free to enhance to your
      > liking:
      >
      > :map zm :let @/=expand("<cword>") <BAR> wincmd w <BAR> execute 'normal
      > n'<CR>
      >
      > Then for successive matches, just type 'n' or '/<CR>', etc. Use normal
      > window motion command to return to original window. E.G.:
      >
      > :wincmd w
      >
      > <C-W>w
      >
      > [mouse click on desired window]
      >
      > Or, better still:
      >
      > :map zm :let @/=expand("<cword>") <BAR> split <BAR> execute 'normal n'<CR>
      >
      > This just splits the current window and starts you at the next occurrence
      of
      > the word under the cursor in the new split. Repeat search as usual.
      Close
      > the split window when you're done. You return to the original window at
      the
      > cursor position you left.
      >
      > HTH:
      >
      > Ref: http://www.vim.org/tips/tip.php?tip_id=798
      >
      > thx,
      > Dave S.
      >
      > *** -----Original Message-----
      > *** From: Chandrasekaran V. [mailto:chandrasekaran_v@...]
      > *** Sent: Friday, October 01, 2004 6:58 PM
      > *** To: vim@...
      > *** Subject: Searching in another (split) window
      > ***
      > ***
      > *** Hi all,
      > *** Is it possible through a key mapping sequence, to do the
      following:
      > ***
      > *** I have a file open in split windows. ie., only two windows are
      > *** active and
      > *** both have the same file.
      > *** I want to initiate a search of a word under the cursor in one
      > *** window and let
      > *** the other window
      > *** show the place where the search-hit happened, while the current window
      > *** doesn't change its
      > *** view. Is this possible to do using some key mapping? Please let me
      know.
      > ***
      > *** Thanks a lot,
      > *** chandra.
      > ***
      > *** _________________________________________________________________
      > *** FREE pop-up blocking with the new MSN Toolbar - get it now!
      > *** http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
      > ***
      >
      >
    • Dave Silvia
      Well, it s rather long winded, but it works. Should probably really be a function. What it does, really, is synchronize 2 windows with the same file to the
      Message 2 of 7 , Oct 2, 2004
      • 0 Attachment
        Well, it's rather long winded, but it works. Should probably really be a
        function. What it does, really, is synchronize 2 windows with the same file
        to the same word and highlight all occurrences of that word in both. If the
        files are different, all bets are off.

        :map zm :let @/=expand("<cword>") <Bar> let l=line('.') <Bar> execute
        'normal b' <Bar> let c=col('.') <Bar> execute 'normal h' <Bar> execute
        'normal n' <Bar> let c=col('.') <Bar> wincmd w <Bar> call cursor(l,c)<CR>

        HTH:

        thx,
        Dave S.

        *** -----Original Message-----
        *** From: V.Chandrasekaran [mailto:chandrasekaran_v@...]
        *** Sent: Saturday, October 02, 2004 4:54 PM
        *** To: Dave Silvia; vim@...
        *** Subject: Re: Searching in another (split) window
        ***
        ***
        *** Hi Dave,
        *** I tried this. This works great. Thanks a lot. However, I
        *** am trying to
        *** refine it a little
        *** bit to suit the exact purpose I am looking for it. Basically I will keep
        *** "wincmd w" as it
        *** is, instead of changing to "split". But I want to somehow do
        *** the following
        *** sequence:
        ***
        *** * get the current line number of the cursor in the primary
        *** window. I could
        *** do this
        *** by 'let l=line(".")' in the current window
        *** * Then, switch to the other window
        *** * Set the cursor at the line number determined by $l as obtained by the
        *** "let" above.
        *** * Then, execute "normal n"
        ***
        *** I am stuck at the fourth step above. I am unable to find a function that
        *** will take the cursor
        *** to the line number specified by a user-defined variable. Any idea?
        ***
        *** ps: The problem with using 'split' for me is that I don't want
        *** to close the
        *** new window
        *** when I am done with the search. Because I may have some more
        *** searches to do
        *** in the
        *** same fashion. If I don't close the new window, the next
        *** invocation of the
        *** command will
        *** open yet another window finally filling with lots of windows.
        ***
        *** Thanks,
        *** chandra.
        ***
        *** ----- Original Message -----
        *** From: "Dave Silvia" <dsilvia@...>
        *** To: "Chandrasekaran V." <chandrasekaran_v@...>; <vim@...>
        *** Sent: Friday, October 01, 2004 6:13 PM
        *** Subject: RE: Searching in another (split) window
        ***
        ***
        *** > This is rather rudimentary, but it works. Feel free to
        *** enhance to your
        *** > liking:
        *** >
        *** > :map zm :let @/=expand("<cword>") <BAR> wincmd w <BAR> execute 'normal
        *** > n'<CR>
        *** >
        *** > Then for successive matches, just type 'n' or '/<CR>', etc.
        *** Use normal
        *** > window motion command to return to original window. E.G.:
        *** >
        *** > :wincmd w
        *** >
        *** > <C-W>w
        *** >
        *** > [mouse click on desired window]
        *** >
        *** > Or, better still:
        *** >
        *** > :map zm :let @/=expand("<cword>") <BAR> split <BAR> execute
        *** 'normal n'<CR>
        *** >
        *** > This just splits the current window and starts you at the
        *** next occurrence
        *** of
        *** > the word under the cursor in the new split. Repeat search as usual.
        *** Close
        *** > the split window when you're done. You return to the
        *** original window at
        *** the
        *** > cursor position you left.
        *** >
        *** > HTH:
        *** >
        *** > Ref: http://www.vim.org/tips/tip.php?tip_id=798
        *** >
        *** > thx,
        *** > Dave S.
        *** >
        *** > *** -----Original Message-----
        *** > *** From: Chandrasekaran V. [mailto:chandrasekaran_v@...]
        *** > *** Sent: Friday, October 01, 2004 6:58 PM
        *** > *** To: vim@...
        *** > *** Subject: Searching in another (split) window
        *** > ***
        *** > ***
        *** > *** Hi all,
        *** > *** Is it possible through a key mapping sequence, to do the
        *** following:
        *** > ***
        *** > *** I have a file open in split windows. ie., only two windows are
        *** > *** active and
        *** > *** both have the same file.
        *** > *** I want to initiate a search of a word under the cursor in one
        *** > *** window and let
        *** > *** the other window
        *** > *** show the place where the search-hit happened, while the
        *** current window
        *** > *** doesn't change its
        *** > *** view. Is this possible to do using some key mapping? Please let me
        *** know.
        *** > ***
        *** > *** Thanks a lot,
        *** > *** chandra.
        *** > ***
        *** > *** _________________________________________________________________
        *** > *** FREE pop-up blocking with the new MSN Toolbar - get it now!
        *** > *** http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
        *** > ***
        *** >
        *** >
      • V.Chandrasekaran
        Thank you. Will give this a try. -chandra. ... From: Dave Silvia To: V.Chandrasekaran ;
        Message 3 of 7 , Oct 2, 2004
        • 0 Attachment
          Thank you. Will give this a try.

          -chandra.

          ----- Original Message -----
          From: "Dave Silvia" <dsilvia@...>
          To: "V.Chandrasekaran" <chandrasekaran_v@...>; <vim@...>
          Sent: Saturday, October 02, 2004 5:46 PM
          Subject: RE: Searching in another (split) window


          > Well, it's rather long winded, but it works. Should probably really be a
          > function. What it does, really, is synchronize 2 windows with the same
          file
          > to the same word and highlight all occurrences of that word in both. If
          the
          > files are different, all bets are off.
          >
          > :map zm :let @/=expand("<cword>") <Bar> let l=line('.') <Bar> execute
          > 'normal b' <Bar> let c=col('.') <Bar> execute 'normal h' <Bar> execute
          > 'normal n' <Bar> let c=col('.') <Bar> wincmd w <Bar> call cursor(l,c)<CR>
          >
          > HTH:
          >
          > thx,
          > Dave S.
          >
          > *** -----Original Message-----
          > *** From: V.Chandrasekaran [mailto:chandrasekaran_v@...]
          > *** Sent: Saturday, October 02, 2004 4:54 PM
          > *** To: Dave Silvia; vim@...
          > *** Subject: Re: Searching in another (split) window
          > ***
          > ***
          > *** Hi Dave,
          > *** I tried this. This works great. Thanks a lot. However, I
          > *** am trying to
          > *** refine it a little
          > *** bit to suit the exact purpose I am looking for it. Basically I will
          keep
          > *** "wincmd w" as it
          > *** is, instead of changing to "split". But I want to somehow do
          > *** the following
          > *** sequence:
          > ***
          > *** * get the current line number of the cursor in the primary
          > *** window. I could
          > *** do this
          > *** by 'let l=line(".")' in the current window
          > *** * Then, switch to the other window
          > *** * Set the cursor at the line number determined by $l as obtained by
          the
          > *** "let" above.
          > *** * Then, execute "normal n"
          > ***
          > *** I am stuck at the fourth step above. I am unable to find a function
          that
          > *** will take the cursor
          > *** to the line number specified by a user-defined variable. Any idea?
          > ***
          > *** ps: The problem with using 'split' for me is that I don't want
          > *** to close the
          > *** new window
          > *** when I am done with the search. Because I may have some more
          > *** searches to do
          > *** in the
          > *** same fashion. If I don't close the new window, the next
          > *** invocation of the
          > *** command will
          > *** open yet another window finally filling with lots of windows.
          > ***
          > *** Thanks,
          > *** chandra.
          > ***
          > *** ----- Original Message -----
          > *** From: "Dave Silvia" <dsilvia@...>
          > *** To: "Chandrasekaran V." <chandrasekaran_v@...>; <vim@...>
          > *** Sent: Friday, October 01, 2004 6:13 PM
          > *** Subject: RE: Searching in another (split) window
          > ***
          > ***
          > *** > This is rather rudimentary, but it works. Feel free to
          > *** enhance to your
          > *** > liking:
          > *** >
          > *** > :map zm :let @/=expand("<cword>") <BAR> wincmd w <BAR> execute
          'normal
          > *** > n'<CR>
          > *** >
          > *** > Then for successive matches, just type 'n' or '/<CR>', etc.
          > *** Use normal
          > *** > window motion command to return to original window. E.G.:
          > *** >
          > *** > :wincmd w
          > *** >
          > *** > <C-W>w
          > *** >
          > *** > [mouse click on desired window]
          > *** >
          > *** > Or, better still:
          > *** >
          > *** > :map zm :let @/=expand("<cword>") <BAR> split <BAR> execute
          > *** 'normal n'<CR>
          > *** >
          > *** > This just splits the current window and starts you at the
          > *** next occurrence
          > *** of
          > *** > the word under the cursor in the new split. Repeat search as usual.
          > *** Close
          > *** > the split window when you're done. You return to the
          > *** original window at
          > *** the
          > *** > cursor position you left.
          > *** >
          > *** > HTH:
          > *** >
          > *** > Ref: http://www.vim.org/tips/tip.php?tip_id=798
          > *** >
          > *** > thx,
          > *** > Dave S.
          > *** >
          > *** > *** -----Original Message-----
          > *** > *** From: Chandrasekaran V. [mailto:chandrasekaran_v@...]
          > *** > *** Sent: Friday, October 01, 2004 6:58 PM
          > *** > *** To: vim@...
          > *** > *** Subject: Searching in another (split) window
          > *** > ***
          > *** > ***
          > *** > *** Hi all,
          > *** > *** Is it possible through a key mapping sequence, to do the
          > *** following:
          > *** > ***
          > *** > *** I have a file open in split windows. ie., only two windows are
          > *** > *** active and
          > *** > *** both have the same file.
          > *** > *** I want to initiate a search of a word under the cursor in one
          > *** > *** window and let
          > *** > *** the other window
          > *** > *** show the place where the search-hit happened, while the
          > *** current window
          > *** > *** doesn't change its
          > *** > *** view. Is this possible to do using some key mapping? Please let
          me
          > *** know.
          > *** > ***
          > *** > *** Thanks a lot,
          > *** > *** chandra.
          > *** > ***
          > *** > ***
          _________________________________________________________________
          > *** > *** FREE pop-up blocking with the new MSN Toolbar - get it now!
          > *** > *** http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
          > *** > ***
          > *** >
          > *** >
          >
          >
        • Keith Roberts
          ... Try this one: map ,/n :let @/=expand( ) wincmd p exec norm nzz let pattrn = % .line( . ). l .@/ exec match Error
          Message 4 of 7 , Oct 4, 2004
          • 0 Attachment
            >-----Original Message-----
            >From: Chandrasekaran V. [mailto:chandrasekaran_v@...]
            >Sent: Friday, October 01, 2004 3:58 PM
            >To: vim@...
            >Subject: Searching in another (split) window
            >
            >Hi all,
            > Is it possible through a key mapping sequence, to do the following:
            >
            >I have a file open in split windows. ie., only two windows are
            >active and both have the same file.
            >I want to initiate a search of a word under the cursor in one
            >window and let the other window show the place where the
            >search-hit happened, while the current window doesn't change
            >its view. Is this possible to do using some key mapping?
            >Please let me know.
            >
            > Thanks a lot,
            > chandra.

            Try this one:

            map ,/n :let @/=expand("<cword>")<bar>wincmd p<bar>exec 'norm
            nzz'<bar>let pattrn = '\%'.line(".").'l'.@/<bar>exec 'match Error
            /'.pattrn.'/'<bar>wincmd p<cr>

            [there's a space after 'norm, and another after Error]

            --
            Keith
          • Keith Roberts
            ... Here s another one to search for a user-input string instead of (defaulting to whatever the last search was]. map ,/s :let @/=input( String:
            Message 5 of 7 , Oct 4, 2004
            • 0 Attachment
              > -----Original Message-----
              > From: Keith Roberts [mailto:kroberts@...]
              > Sent: Monday, October 04, 2004 9:53 AM
              > To: Chandrasekaran V.; vim@...
              > Subject: RE: Searching in another (split) window
              >
              Chandrasekaran V. wrote:
              >> Hi all,
              >> Is it possible through a key mapping sequence, to do the
              >> following:
              >>
              >> I have a file open in split windows. ie., only two windows are
              >> active and both have the same file. I want to initiate a search of a
              >> word under the cursor in one window and let the other window show
              >> the place where the search-hit happened, while the current window
              >> doesn't change its view. Is this possible to do using some key
              >> mapping? Please let me know.
              >>
              >> Thanks a lot,
              >> chandra.
              >
              > Try this one:
              >
              > map ,/n :let @/=expand("<cword>")<bar>wincmd p<bar>exec 'norm
              > nzz'<bar>let pattrn = '\%'.line(".").'l'.@/<bar>exec 'match
              > Error /'.pattrn.'/'<bar>wincmd p<cr>
              >
              > [there's a space after 'norm, and another after Error]
              >
              > --
              > Keith

              Here's another one to search for a user-input string instead of <cword>
              (defaulting to whatever the last search was].

              map ,/s :let @/=input('String: ',@/)<bar>wincmd p<bar>exec 'norm
              nzz'<bar>let pattrn = '\%'.line(".").'l'.@/<bar>exec 'match Error
              /'.pattrn.'/'<bar>wincmd p<cr>

              --
              Keith
            Your message has been successfully submitted and would be delivered to recipients shortly.