Re: Ignore matches that are commented out - was "How to edit a macro"
- Yakov Lerner wrote:
> On 11/1/06, Robert Cussons <r.cussons@...> wrote:It does seem to be very useful, I shall check it more often.
>> 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!
>Thanks Yakov, I will give this function a try over the next few days and
> 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
> 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,
see if it does what I want.