45 lines
1.5 KiB
VimL
45 lines
1.5 KiB
VimL
" 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')
|
|
let $RG_DEFAULT_COMMAND = 'rg --files --hidden --follow --glob "!.git/*"'
|
|
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
|
|
|
|
" Search in files with ripgrep + preview with bat
|
|
function! Fzf_dev()
|
|
let l:fzf_files_options = '--preview "bat --style=numbers,changes --color always {2..-1} | head -'.&lines.'"'
|
|
|
|
function! s:files()
|
|
let l:files = split(system($RG_DEFAULT_COMMAND), '\n')
|
|
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
|