-
-
Save curtismckee/c687043e86d1c0063f11e50b1ace4e9c to your computer and use it in GitHub Desktop.
File preview with FZF, RG, Bat, and Devicons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nnoremap <silent> <leader>e :call Fzf_dev()<CR> | |
" ripgrep | |
if executable('rg') | |
let $FZF_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 | |
" Files + devicons | |
function! Fzf_dev() | |
let l:fzf_files_options = '--preview "bat --theme="OneHalfDark" --style=numbers,changes --color always {2..-1} | head -'.&lines.'"' | |
function! s:files() | |
let l:files = split(system($FZF_DEFAULT_COMMAND), '\n') | |
return s:prepend_icon(l:files) | |
endfunction | |
function! s:prepend_icon(candidates) | |
let l:result = [] | |
for l:candidate in a:candidates | |
let l:filename = fnamemodify(l:candidate, ':p:t') | |
let l:icon = WebDevIconsGetFileTypeSymbol(l:filename, isdirectory(l:filename)) | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment