Ignore node_modules with vim-fzf



我定义了一个函数来搜索文件名(<C-P>(,并使用fzf.vimAg插件从git根目录中异步搜索字符串(<C-F>(。但是,我无法操纵定义以忽略node_modules目录。vim 脚本太难调试,没有控制台可以打印任何内容。

有没有 vim 脚本方面的专家可以帮助我解决这个问题。提前非常感谢

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>

最后,我想出了一个解决方法,将fzf#vim#files替换为:Gfiles

新配置silent! nmap <C-P> :GFiles<CR>

<C-F>映射与问题中相同。

:GFiles解决方案的缺点是搜索结果中不包含未添加到git的文件(未跟踪的文件(。它们都可以通过git add . -A添加

此解决方案的优点是在搜索结果中忽略.gitignore中的所有文件

我能够通过在.bash_profile中定义env var来解决此问题。

export FZF_DEFAULT_COMMAND='ag --nocolor --ignore node_modules -g ""'

最新更新