mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-07 13:14:30 +08:00
[fzf#vim#grep / Ag / Rg / RG] Multi-line display for narrow screens (#1549)
This commit is contained in:
14
README.md
14
README.md
@@ -176,9 +176,21 @@ let g:fzf_vim.preview_window = []
|
|||||||
#### Command-level options
|
#### Command-level options
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
" [Buffers] Jump to the existing window if possible
|
" [Buffers] Jump to the existing window if possible (default: 0)
|
||||||
let g:fzf_vim.buffers_jump = 1
|
let g:fzf_vim.buffers_jump = 1
|
||||||
|
|
||||||
|
" [Ag|Rg|RG] Display path on a separate line for narrow screens (default: 0)
|
||||||
|
" * Requires Perl and fzf 0.53.0 or later
|
||||||
|
let g:fzf_vim.grep_multi_line = 0
|
||||||
|
" PATH:LINE:COL:LINE
|
||||||
|
let g:fzf_vim.grep_multi_line = 1
|
||||||
|
" PATH:LINE:COL:
|
||||||
|
" LINE
|
||||||
|
let g:fzf_vim.grep_multi_line = 2
|
||||||
|
" PATH:LINE:COL:
|
||||||
|
" LINE
|
||||||
|
" (empty line)
|
||||||
|
|
||||||
" [[B]Commits] Customize the options used by 'git log':
|
" [[B]Commits] Customize the options used by 'git log':
|
||||||
let g:fzf_vim.commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
|
let g:fzf_vim.commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
|
||||||
|
|
||||||
|
|||||||
@@ -851,7 +851,17 @@ function! s:ag_handler(name, lines)
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let list = map(filter(a:lines[1:], 'len(v:val)'), 's:ag_to_qf(v:val)')
|
let multi_line = min([s:conf('grep_multi_line', 0), 2])
|
||||||
|
let lines = []
|
||||||
|
if multi_line && executable('perl')
|
||||||
|
for idx in range(1, len(a:lines), multi_line + 1)
|
||||||
|
call add(lines, join(a:lines[idx:idx + multi_line + 1], ''))
|
||||||
|
endfor
|
||||||
|
else
|
||||||
|
let lines = a:lines[1:]
|
||||||
|
endif
|
||||||
|
|
||||||
|
let list = map(filter(lines, 'len(v:val)'), 's:ag_to_qf(v:val)')
|
||||||
if empty(list)
|
if empty(list)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
@@ -893,6 +903,19 @@ function! fzf#vim#ag_raw(command_suffix, ...)
|
|||||||
return call('fzf#vim#grep', extend(['ag --nogroup --column --color '.a:command_suffix, 1], a:000))
|
return call('fzf#vim#grep', extend(['ag --nogroup --column --color '.a:command_suffix, 1], a:000))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:grep_multi_line(opts)
|
||||||
|
" TODO: Non-global option
|
||||||
|
let multi_line = s:conf('grep_multi_line', 0)
|
||||||
|
if multi_line && executable('perl')
|
||||||
|
let opts = copy(a:opts)
|
||||||
|
let opts.options = extend(copy(opts.options), ['--read0', '--highlight-line'])
|
||||||
|
let delim = multi_line > 1 ? '\n\0' : '\0'
|
||||||
|
return [opts, printf(" | perl -pe 's/\\n/%s/; s/^([^:]+:){2,3}/$&\\n /'", delim)]
|
||||||
|
endif
|
||||||
|
|
||||||
|
return [a:opts, '']
|
||||||
|
endfunction
|
||||||
|
|
||||||
" command (string), [spec (dict)], [fullscreen (bool)]
|
" command (string), [spec (dict)], [fullscreen (bool)]
|
||||||
function! fzf#vim#grep(grep_command, ...)
|
function! fzf#vim#grep(grep_command, ...)
|
||||||
let args = copy(a:000)
|
let args = copy(a:000)
|
||||||
@@ -919,9 +942,11 @@ function! fzf#vim#grep(grep_command, ...)
|
|||||||
return s:ag_handler(get(opts, 'name', name), a:lines)
|
return s:ag_handler(get(opts, 'name', name), a:lines)
|
||||||
endfunction
|
endfunction
|
||||||
let opts['sink*'] = remove(opts, 'sink')
|
let opts['sink*'] = remove(opts, 'sink')
|
||||||
|
let [opts, suffix] = s:grep_multi_line(opts)
|
||||||
|
let command = a:grep_command . suffix
|
||||||
try
|
try
|
||||||
let prev_default_command = $FZF_DEFAULT_COMMAND
|
let prev_default_command = $FZF_DEFAULT_COMMAND
|
||||||
let $FZF_DEFAULT_COMMAND = a:grep_command
|
let $FZF_DEFAULT_COMMAND = command
|
||||||
return s:fzf(name, opts, args)
|
return s:fzf(name, opts, args)
|
||||||
finally
|
finally
|
||||||
let $FZF_DEFAULT_COMMAND = prev_default_command
|
let $FZF_DEFAULT_COMMAND = prev_default_command
|
||||||
@@ -946,11 +971,15 @@ function! fzf#vim#grep2(command_prefix, query, ...)
|
|||||||
\ 'source': s:is_win ? 'cd .' : ':',
|
\ 'source': s:is_win ? 'cd .' : ':',
|
||||||
\ 'options': ['--ansi', '--prompt', toupper(name).'> ', '--query', a:query,
|
\ 'options': ['--ansi', '--prompt', toupper(name).'> ', '--query', a:query,
|
||||||
\ '--disabled',
|
\ '--disabled',
|
||||||
\ '--bind', 'start:reload:'.a:command_prefix.' '.fzf#shellescape(a:query),
|
|
||||||
\ '--bind', 'change:reload:'.a:command_prefix.' {q}'.fallback,
|
|
||||||
\ '--multi', '--bind', 'alt-a:select-all,alt-d:deselect-all',
|
\ '--multi', '--bind', 'alt-a:select-all,alt-d:deselect-all',
|
||||||
\ '--delimiter', ':', '--preview-window', '+{2}-/2']
|
\ '--delimiter', ':', '--preview-window', '+{2}-/2']
|
||||||
\}
|
\}
|
||||||
|
|
||||||
|
let [opts, suffix] = s:grep_multi_line(opts)
|
||||||
|
let suffix = escape(suffix, '{')
|
||||||
|
call extend(opts.options, ['--bind', 'start:reload:'.a:command_prefix.' '.fzf#shellescape(a:query).suffix])
|
||||||
|
call extend(opts.options, ['--bind', 'change:reload:'.a:command_prefix.' {q}'.suffix.fallback])
|
||||||
|
|
||||||
if len(args) && type(args[0]) == s:TYPE.bool
|
if len(args) && type(args[0]) == s:TYPE.bool
|
||||||
call remove(args, 0)
|
call remove(args, 0)
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user