fernandoacorreia / homefiles

Files from my home directory that I'm likely to reuse across machines.
MIT License
1 stars 0 forks source link

Find command #7

Open fernandoacorreia opened 7 years ago

fernandoacorreia commented 7 years ago

From https://medium.com/@crashybang/supercharge-vim-with-fzf-and-ripgrep-d4661fc853d2:

Now we are going to define our own :Find command so we can leverage rg for more than just finding files. To do this add the following to your .vimrc:

" --column: Show column number
" --line-number: Show line number
" --no-heading: Do not show file headings in results
" --fixed-strings: Search term as a literal string
" --ignore-case: Case insensitive search
" --no-ignore: Do not respect .gitignore, etc...
" --hidden: Search hidden files and folders
" --follow: Follow symlinks
" --glob: Additional conditions for search (in this case ignore everything in the .git/ folder)
" --color: Search color options
command! -bang -nargs=* Find call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --glob "!.git/*" --color "always" '.shellescape(<q-args>), 1, <bang>0)

Now open up vim again and run :Find term where term is the string you want to search, this will open up a window similar to :Files but will only list files that contain the term searched.

fernandoacorreia commented 7 years ago
" ripgrep
if empty(glob("~/bin/rg"))
  execute '!curl -Ls https://github.com/BurntSushi/ripgrep/releases/download/0.3.1/ripgrep-0.3.1-x86_64-unknown-linux-musl.tar.gz | tar xzf - -C ~/bin --strip=1 --wildcards "*/rg"'
endif
command! -bang -nargs=* Find call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --hidden --glob "!.git/*" --follow --color "always" '.shellescape(<q-args>), 1, <bang>0)
set grepprg=rg\ --vimgrep\ --no-heading
set grepformat=%f:%l:%c:%m