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

Re: Ignore matches that are commented out - was "How to edit a macro"

Expand Messages
  • Robert Cussons
    ... It does seem to be very useful, I shall check it more often. ... Thanks Yakov, I will give this function a try over the next few days and see if it does
    Message 1 of 7 , Nov 2, 2006
    • 0 Attachment
      Yakov Lerner wrote:
      > On 11/1/06, Robert Cussons <r.cussons@...> wrote:
      >
      >> Hi everyone,
      >>
      >> In a C programme for example is there a way to get Vim to ignore matches
      >> that are commented out when searching for a string?
      >
      >
      > I found another solution, posted on this list in 2004 (not by me).
      > This list archive is full of gold!

      It does seem to be very useful, I shall check it more often.

      >
      > http://marc.theaimsgroup.com/?l=vim&m=108617062626551&w=2
      >
      > Subject: Re: How to skip comments during search
      > From: "vim" <vim9527 () 21cn ! com>
      > Date: 2004-06-02 10:06:43
      > Message-ID: 000f01c44889$54e17e40$ab00a8c0 () zhao
      >
      > function! SearchNoComment(str, opt)
      > let b:found = 0
      > while (b:found == 0)
      > call search(a:str, a:opt)
      > let b:name=synIDattr( synID(line('.'), col('.'), 1), "name")
      > "Whether it's within a comment?
      > if b:name !~? "comment"
      > let b:found=1
      > endif
      > endwhile
      > endfunction
      >
      > and, then map the n and N command as follows:
      > nnoremap n :silent call SearchNoComment('<C-R>=@/<CR>', 'f')<CR>
      > nnoremap N :silent call SearchNoComment('<C-R>=@/<CR>', 'b')<CR>
      >
      > For the first search, you use /pattern as normal, for the later search of
      > the same pattern, just use n or N.
      > It won't work for the first search, unless you use :call
      > SearchNoComment('pattern', 'f')
      > I think it's impossible to enable such a feature in a
      > incremental search, is it?
      >
      > Note, you needn't to map # and * command, it's naturally n and N,
      > separately.
      >

      Thanks Yakov, I will give this function a try over the next few days and
      see if it does what I want.
    Your message has been successfully submitted and would be delivered to recipients shortly.