On Wed, March 10, 2010 6:16 pm, Andy Wokula wrote:
> In a mapping:
>
>      :nn <expr> n  &ws \|\| search("","nW")  ? "n" : ":bnext<CR>ggn"
>      :nn <expr> N  &ws \|\| search("","bnW") ? "N" : ":bprev<CR>G$N"
>

I tried using vimgrep:

fu! <sid>Files()
    let list=[]
    for id in range(1,bufnr('$'))
        if buflisted(id)
           call add(list, fnamemodify(bufname(id), ':p'))
        endif
    endfor
    return list
endfu

fu! <sid>Search()
        let a=input('/')
        if !empty(a)
            return ':silent vimgrep /' . escape(a,'/') .'/gj ' .
join(<sid>Files()) . "\n:redraw!\n"
        else
            return ":redraw!\n"
        endif
endfu

fu! <sid>MapKeys(mode)
    if a:mode
        cnoremap <expr> / <sid>Search()
        noremap n :cn<CR>
        noremap N :cp<CR>
    else
        cunmap /
        unmap n
        unmap N
    endif
endfu

has some drawbacks too:
- does not work, if you need / within the search phrase
  (at least I did not succeed checking if the cursor is
   on the first char, getcmdpos() does not seem to work
   in an expression mapping)
- does probably not search unnamed buffers
- ignores the fact, that n/N can switch direction
- does not search unlisted files
- probably some more ...

regards,
Christian

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to