On 11/1/06, Robert Cussons <[EMAIL PROTECTED]> 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!

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.

Reply via email to