grep pattern in vim

5 Points

sooop sooop

10 years ago

search pattern in current buffer and display search result in quick fix.

function! SFancyGrep(kwd)
    if len(a:kwd) == 0
        let s:kwd = input('Pattern: ')
    else
        let s:kwd = a:kwd
    endif
    exec "vimgrep /".s:kwd."/ %"
    exec "copen"
endfunction 
nnoremap <leader>fg :call SFancyGrep("")<cr>
nnoremap <leader>fw viwy:call SFancyGrep("<c-r>0")<cr>
vnoremap <leader>fg y:call SFancyGrep("<c-r>0")<cr>