Created
November 16, 2018 19:16
-
-
Save danmikita/d855174385b3059cd6bc399ad799555e 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 |
Any chance to make this compatible with fzf_action (CTRL-T, CTRL-X, etc).
+1, useless without that. But thx, it is beautiful.
Is it just me or calling this function takes at least 10 seconds?
Is it just me or calling this function takes at least 10 seconds?
It only takes ~500ms for me... But I am running on a newer Macbook Pro with at least an i7 and 16Gb of ram...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot sir. Nice work!