2021-06-11 22:55:32 +02:00
|
|
|
" ripgrep
|
|
|
|
" if executable('ug')
|
|
|
|
" let $FZF_DEFAULT_COMMAND = 'ug'
|
|
|
|
" set grepprg=ugrep\ -RInk\ -j\ -u\ --tabs=1\ --ignore-files
|
|
|
|
" set grepformat=%f:%l:%c:%m,%f+%l+%c+%m,%-G%f\\\|%l\\\|%c\\\|%m
|
|
|
|
" endif
|
|
|
|
if executable('rg')
|
2022-01-28 15:57:47 +01:00
|
|
|
let $RG_DEFAULT_COMMAND = 'rg --files --hidden --follow --glob "!.git/*"'
|
2021-06-11 22:55:32 +02:00
|
|
|
set grepprg=rg\ --vimgrep
|
|
|
|
command! -bang -nargs=* Find call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --ignore-case --hidden --follow --glob "!.git/*" --color "always" '.shellescape(<q-args>).'| tr -d "\017"', 1, <bang>0)
|
|
|
|
endif
|
|
|
|
|
2022-01-28 15:57:47 +01:00
|
|
|
" Search in files with ripgrep + preview with bat
|
2021-06-11 22:55:32 +02:00
|
|
|
function! Fzf_dev()
|
|
|
|
let l:fzf_files_options = '--preview "bat --style=numbers,changes --color always {2..-1} | head -'.&lines.'"'
|
|
|
|
|
|
|
|
function! s:files()
|
2022-01-28 15:57:47 +01:00
|
|
|
let l:files = split(system($RG_DEFAULT_COMMAND), '\n')
|
2021-06-11 22:55:32 +02:00
|
|
|
return s:format_list(l:files)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:format_list(candidates)
|
|
|
|
let l:result = []
|
|
|
|
for l:candidate in a:candidates
|
|
|
|
let l:filename = fnamemodify(l:candidate, ':p:t')
|
|
|
|
let l:icon = ">-"
|
|
|
|
call add(l:result, printf('%s %s', l:icon, l:candidate))
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:result
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:edit_file(item)
|
|
|
|
let l:pos = stridx(a:item, ' ')
|
|
|
|
let l:file_path = a:item[pos+1:-1]
|
|
|
|
execute 'silent e' l:file_path
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call fzf#run({
|
|
|
|
\ 'source': <sid>files(),
|
|
|
|
\ 'sink': function('s:edit_file'),
|
|
|
|
\ 'options': '-m ' . l:fzf_files_options,
|
|
|
|
\ 'down': '40%' })
|
|
|
|
endfunction
|