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

Feature - Action of multiple selection on Ag/Rg behavior like Files #1374

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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ let g:fzf_tags_command = 'ctags -R'

" [Commands] --expect expression for directly executing the command
let g:fzf_commands_expect = 'alt-enter,ctrl-x'

" [Rg \ Ag] Actions on multiple lines will have the same behavior as `Files` command.
" Default behavior - insert option into quickfix list.
let g:ag_action_like_files = 1
```

### Advanced customization
Expand Down
32 changes: 20 additions & 12 deletions autoload/fzf/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,18 @@ function! s:ag_to_qf(line, has_column)
return dict
endfunction

function! s:ag_open_at_line(cmd, line, has_column)
try
call s:open(a:cmd, a:line.filename)
execute a:line.lnum
if a:has_column
call cursor(0, a:line.col)
endif
normal! zvzz
catch
endtry
endfunction

function! s:ag_handler(lines, has_column)
if len(a:lines) < 2
return
Expand All @@ -747,18 +759,14 @@ function! s:ag_handler(lines, has_column)
return
endif

let first = list[0]
try
call s:open(cmd, first.filename)
execute first.lnum
if a:has_column
call cursor(0, first.col)
endif
normal! zvzz
catch
endtry

call s:fill_quickfix(list)
if get(g:, 'ag_action_like_files', 0)
for line in list
call s:ag_open_at_line(cmd, line, a:has_column)
endfor
else
call s:ag_open_at_line(cmd, list[0], a:has_column)
call s:fill_quickfix(list)
endif
endfunction

" query, [[ag options], options]
Expand Down