Skip to content

Instantly share code, notes, and snippets.

@sajoku
Forked from bag-man/post.md
Created September 25, 2017 14:56
Show Gist options
  • Save sajoku/c3e12d06f5dcb6bca85402dbc46837ab to your computer and use it in GitHub Desktop.
Save sajoku/c3e12d06f5dcb6bca85402dbc46837ab to your computer and use it in GitHub Desktop.
fzf + rgrep + vim mini tutorial

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment