to search for files only by extension/filetype, try this in command line:
rg . --files -g "*.{py}"
with this im searching only for python files
my output:
> rg . --files -g "*.{py}"
./another.py
./colors_do_not_apply.py
to exclude a directory from ripgrep
if you want to search all content from files
at current directory:
> rg --column --line-number --no-heading --color=always --smart-case --hidden -g "\!.git" .
notice that:
--hidden
is for hidden files
-g "\!.git"
is for ignoring
git folder (you can do the same with others)
note:
i used "\!.git"
, that is only used in terminal (my zsh explodes without ! escaped), in vim you can use it as "!.git"
if you want to search only for files and exlcude git folder at current dir:
> rg --hidden -g "\!.git" --files .
search in sub-directory is made automatically so you dont need to worry
finally
i saw you copy pasted a fancy function from fzf.vim on github, i use that too :)
here is my function:
" search for content in files in current project, including hidden ones and ignoring git
function! SearchContentInFiles(query, fullscreen)
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case --hidden -g "!.git" -- %s || true'
let initial_command = printf(command_fmt, shellescape(a:query))
let reload_command = printf(command_fmt, '{q}')
let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command, '--exact', '--pointer=@', '-i', '-m', '--cycle', '--border=none', '--marker=*', '--ansi', '--preview-window=left,50%', '--bind=alt-bspace:backward-kill-word,ctrl-x:beginning-of-line+kill-line,ctrl-a:select-all', '--color=16,fg+:bright-red,hl:bright-blue,hl+:green,query:blue,prompt:yellow,info:magenta,pointer:bright-yellow,marker:bright-blue,spinner:bright-blue,header:blue', '--prompt=content from files(+hidden) (git ignored) at . > ']}
call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction
command! -nargs=* -bang SCIF call SearchContentInFiles(<q-args>, <bang>0)
nnoremap <silent> <S-F> :SCIF!<CR>
well, its quite big, i know. this is the best i've got.
the only differences are:
- in
command_fmt
i added extra args for hidden files and exclusion of git folder
- the name of the function
- fzf options (there are a lot of options), more exactly these options:
'--exact' - exact match
'--pointer=@',
'-i',
'-m',
'--cycle', (repeat after end)
'--border=none',
'--marker=*',
'--ansi', (enable colors)
'--preview-window=left,50%',
'--bind=alt-bspace:backward-kill-word,ctrl-x:beginning-of-line+kill-line,ctrl-a:select-all', (some keybindings)
'--color=16,fg+:bright-red,hl:bright-blue,hl+:green,query:blue,prompt:yellow,info:magenta,pointer:bright-yellow,marker:bright-blue,spinner:bright-blue,header:blue', (color scheme)
'--prompt=content from files(+hidden) (git ignored) at . > ' (prompt text)
ofc, you can integrate every above command in vim.
hope these help.