I have defined a function to search for filename (<C-P>
), and a string (<C-F>
) from git root directory asynchronously with fzf.vim
plugin (I also have Ag
installed). However, I can not manipulate the definition to ignore node_modules
directory. The vim script is too hard to debug, there is no console to print anything.
Is there any expert in vim script that can help me sort this out. Many thanks in advance
let s:git_path = substitute(system("git rev-parse --show-toplevel 2>/dev/null"), '\n', '', '')
function! s:ag_git_root(query, ...)
if type(a:query) != type('')
return s:warn('Invalid query argument')
endif
let query = empty(a:query) ? '^(?=.)' : a:query
let args = copy(a:000)
let ag_opts = len(args) > 1 && type(args[0]) == s:TYPE.string ? remove(args, 0) : ''
let command = ag_opts . ' ' . fzf#shellescape(query) . ' ' . s:git_path
return call('fzf#vim#ag_raw', insert(args, command, 0))
endfunction
command! -bang -nargs=* A
\ call s:ag_git_root(<q-args>, <bang>0)
command! -bang -nargs=? F
\ call fzf#vim#files(s:git_path, <bang>0)
silent! nmap <C-P> :F<CR>
silent! nmap <C-F> :A<CR>
ag
honors your.gitignore
by default so if you havenode_modules
there it should be ignored. – Orelunode_modules/
is already included in.gitignore
, but it still is included in search result. I thinkfzf#vim#files# does not use
ag` internally (I could not debug to see which is used) . Eventually, I figured out the solution with a minor demerit. check out my answer below – Concurrence