I've always had fzf and ripgrep on my radar, and I've finally gotten around to using them together. Good lord it makes a world of difference, especially when added to Vim as well as Bash.
Add the following snippet to your ~/.bashrc, this add's fzf keybindings to bash and gets fzf to use ripgrep by default for faster searching.
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow --glob "!.git/*"'
bind -x '"\C-p": vim $(fzf);'
Okay now what can you do?
- Ctrl + r - search through bash history with fzf
- Ctrl + p - edit a file in vim from fzf
- mv dir/** - expand a directory with (**) and select from fzf
- Alt + c - change directory from fzf
- Ctrl + t - insert file from fzf into command
Neat right! Now if you are a vim user there is more, add the fzf plugin to your ~/.vimrc, along with this snippet. Obviously customise the bindings, and excludes / includes to your workflows!
let g:rg_command = '
\ rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --color "always"
\ -g "*.{js,json,php,md,styl,jade,html,config,py,cpp,c,go,hs,rb,conf}"
\ -g "!*.{min.js,swp,o,zip}"
\ -g "!{.git,node_modules,vendor}/*" '
command! -bang -nargs=* F call fzf#vim#grep(g:rg_command .shellescape(<q-args>), 1, <bang>0)
You now have a killer free text search with :F
that uses ripgrep and is faster than any I've seen before.
I've done more with this, but want to leave it there for now. There are even more goodies in my .vimrc, and in my .bashrc, including auto installing fzf and ripgrep (admittedly hackily) from the .vimrc and a nice snippet that uses fzf for git logs.
Hi
Awesome article, thanks so much. Any idea where I should start digging in order to get this working?
mv dir/** - expand a directory with (**) and select from fzf
On tabbing I receive the arbitrary linux message
Do you want to expand all n possibilities?
Everything else works like a charm 🚀