Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore node_modules with vim-fzf

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>
like image 247
transang Avatar asked Jun 29 '18 01:06

transang


1 Answers

Finally, I figured out a workaround by replacing fzf#vim#files with :Gfiles

New configuration is silent! nmap <C-P> :GFiles<CR>

<C-F> mapping is kept the same as in the question.

The demerit of this :GFiles solution is that files not added to git (untracked files) are not included in the search results. They all can be added via git add . -A

The merit of this solution is that all files in .gitignore is ignored in the search results

like image 178
transang Avatar answered Sep 28 '22 09:09

transang