-
-
Save mnabila/060fa1aa07017742c2e9dc98cc59414c to your computer and use it in GitHub Desktop.
File preview with FZF, RG, Bat, and Devicons
This file contains hidden or 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.reddit.com/r/vim/comments/9xpb18/file_preview_with_fzf_rg_bat_and_devicons/