diff options
-rw-r--r-- | .vim/after/plugin/fzf.vim | 91 |
1 files changed, 67 insertions, 24 deletions
diff --git a/.vim/after/plugin/fzf.vim b/.vim/after/plugin/fzf.vim index 9234eb4..3c7d03d 100644 --- a/.vim/after/plugin/fzf.vim +++ b/.vim/after/plugin/fzf.vim @@ -1,24 +1,67 @@ -" if executable('fzf') && get(g:, 'loaded_fzf_vim', 0) == 1 -" let g:fzf_command_prefix = 'Fzf' -" -" command! -bang -nargs=* FzfRg -" \ call fzf#vim#grep( -" \ 'rg --hidden --column --line-number --no-heading --color=always --smart-case --glob !.git -- '.shellescape(<q-args>), 1, -" \ fzf#vim#with_preview(), <bang>0) -" -" noremap <leader>ff :FzfFiles<CR> -" noremap <leader>fgf :FzfGFiles<CR> -" noremap <leader>fb :FzfBuffers<CR> -" noremap <leader>fm :FzfHistory<CR> -" noremap <leader>ft :FzfBTags<CR> -" noremap <leader>fT :FzfTags<CR> -" noremap <leader>fa :FzfAg<space> -" noremap <leader>fr :FzfRg<space> -" noremap <leader>fc :FzfCommands<CR> -" noremap <leader>fgc :FzfBCommits<CR> -" noremap <leader>fgC :FzfCommits<CR> -" noremap <leader>fl :FzfBLines<CR> -" noremap <leader>fL :FzfLines<CR> -" -" packadd fzf.vim -" endif +let s:fzf_default_opts = $FZF_DEFAULT_OPTS + +function! s:build_quickfix_list(lines) abort + call setqflist(map(copy(a:lines), '{ "filename": v:val }')) + copen + cc +endfunction + +function! s:format_qf_line(line) abort + let parts = split(a:line, ':') + return { + \ 'filename': parts[0], + \ 'lnum': parts[1], + \ 'col': parts[2], + \ 'text': join(parts[3:], ':') + \ } +endfunction + +function! s:fzf_qf(key, line) abort + let filepath = expand('#' . a:line.bufnr . ':p') + return filepath . ':' . a:line.lnum . ':' . a:line.col . ':' . a:line.text +endfunction + +" TODO make it accept multiple lines +function! s:fzf_qf_sink(line) abort + let line = s:format_qf_line(a:line[0]) + execute 'edit +' . line.lnum . ' ' . line.filename +endfunction + +command! FzfQuickFix call fzf#run({ + \ 'source': map(getqflist(), function('s:fzf_qf')), + \ 'down': 20, + \ 'sink*': function('s:fzf_qf_sink'), + \ 'options': s:fzf_default_opts. ' --multi --prompt "QuickFix> "' + \ }) + +if executable('fzf') && get(g:, 'loaded_fzf', 0) == 1 + let g:fzf_command_prefix = 'Fzf' + + command! -bang -nargs=* FzfRg + \ call fzf#vim#grep( + \ 'rg --hidden --column --line-number --no-heading --color=always --smart-case --glob !.git '.shellescape(<q-args>), 1, + \ fzf#vim#with_preview(), <bang>0) + + noremap <leader>ff :FzfFiles<CR> + noremap <leader>fgf :FzfGFiles<CR> + noremap <leader>fb :FzfBuffers<CR> + noremap <leader>fm :FzfHistory<CR> + noremap <leader>ft :FzfBTags<CR> + noremap <leader>fT :FzfTags<CR> + noremap <leader>fa :FzfAg<space> + noremap <leader>fr :FzfRg<space> + noremap <leader>fc :FzfCommands<CR> + noremap <leader>fgc :FzfBCommits<CR> + noremap <leader>fgC :FzfCommits<CR> + noremap <leader>fl :FzfBLines<CR> + noremap <leader>fL :FzfLines<CR> + noremap <leader>fq :FzfQuickFix<CR> + + let g:fzf_action = { + \ 'ctrl-q': function('s:build_quickfix_list') + \ } + let g:fzf_layout = { 'down': '40%' } + let g:fzf_preview_window = [ 'right:80%:hidden', 'ctrl-/' ] + + packadd fzf.vim +endif |