Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qf buffers support #1492

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions autoload/fzf/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,65 @@ function! fzf#vim#gitfiles(args, ...)
return s:fzf('gfiles-diff', wrapped, a:000)
endfunction

" ------------------------------------------------------------------
" fromqf
" ------------------------------------------------------------------

function! s:_qf_line_handler(lines)
if len(a:lines) < 2
return
endif
normal! m'
let cmd = s:action_for(a:lines[0])
if !empty(cmd) && stridx('edit', cmd) < 0
execute 'silent' cmd
endif

let keys = split(split(a:lines[1], '\t')[0], ':')
echom keys
execute 'buffer' keys[0]
execute keys[1]
normal! ^zvzz
endfunction

function! fzf#vim#_qf_format_buffer(b)
let name = bufname(a:b.bufnr)
let line = a:b.lnum
let name = empty(name) ? '[No Name]' : fnamemodify(name, ":p:~:.")
let flag = a:b.bufnr == bufnr('') ? s:blue('%', 'Conditional') :
\ (a:b.bufnr == bufnr('#') ? s:magenta('#', 'Special') : ' ')
let modified = getbufvar(a:b.bufnr, '&modified') ? s:red(' [+]', 'Exception') : ''
let readonly = getbufvar(a:b.bufnr, '&modifiable') ? '' : s:green(' [RO]', 'Constant')
let extra = join(filter([modified, readonly], '!empty(v:val)'), '')
let target = line == 0 ? name : name.':'.line
let ret=s:strip(printf("%s\t%d\t[%s] %s\t%s\t%s", target, line, s:yellow(a:b.bufnr, 'Number'), flag, name, extra))
return ret
endfunction

function! s:_qf_sort_buffers(...)
let [b1, b2] = map(copy(a:000), 'v:val')
" Using minus between a float and a number in a sort function causes an error
return b1.bufnr < b2.bufnr ? 1 : -1
endfunction

function! fzf#vim#_qf_buflisted_sorted()
return sort(getqflist(), 's:_qf_sort_buffers')
endfunction

function! fzf#vim#qf_buffers(...)
let [query, args] = (a:0 && type(a:1) == type('')) ?
\ [a:1, a:000[1:]] : ['', a:000]
let sorted = fzf#vim#_qf_buflisted_sorted()
let header_lines = '--header-lines=0'
let tabstop = 9
return s:fzf('buffers', {
\ 'source': map(sorted, 'fzf#vim#_qf_format_buffer(v:val)'),
\ 'sink*': s:function('s:_qf_line_handler'),
\ 'options': ['+m', '-x', '--tiebreak=index', header_lines, '--ansi', '-d', '\t', '--with-nth', '3..', '-n', '2,1..2', '--prompt', 'Buf> ', '--query', query, '--preview-window', '+{2}-/2', '--tabstop', tabstop]
\}, args)
endfunction


" ------------------------------------------------------------------
" Buffers
" ------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions plugin/fzf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ call s:defs([
\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(<q-args> == "?" ? { "placeholder": "" } : {}), <bang>0)',
\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(<q-args>, fzf#vim#with_preview(<q-args> == "?" ? { "placeholder": "" } : {}), <bang>0)',
\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(<q-args>, fzf#vim#with_preview({ "placeholder": "{1}" }), <bang>0)',
\'command! -bar -bang -nargs=? -complete=buffer Usages call fzf#vim#qf_buffers(<q-args>, fzf#vim#with_preview({ "placeholder": "{1}" }), <bang>0)',
\'command! -bang -nargs=* Lines call fzf#vim#lines(<q-args>, <bang>0)',
\'command! -bang -nargs=* BLines call fzf#vim#buffer_lines(<q-args>, <bang>0)',
\'command! -bar -bang Colors call fzf#vim#colors(<bang>0)',
Expand Down