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

Add ability to search all open buffers #273

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
20 changes: 20 additions & 0 deletions autoload/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ function! ack#AckWindow(cmd, args) "{{{
call ack#Ack(a:cmd, args)
endfunction "}}}

function! ack#AckBuffers(cmd, args) "{{{
let files = map(filter(copy(getbufinfo()), 'v:val.listed'), 'v:val.bufnr')

" remove duplicated filenames (files appearing in more than one window)
let files = filter(copy(sort(files)), 'index(files,v:val,v:key+1)==-1')
call map(files, "bufname(v:val)")

" remove unnamed buffers as quickfix (empty strings before shellescape)
call filter(files, 'v:val != ""')

" remove directories
call filter(files, {idx, val -> !isdirectory(val)})

" expand to full path (avoid problems with cd/lcd in au QuickFixCmdPre)
let files = map(files, "shellescape(fnamemodify(v:val, ':p'))")
let args = a:args . ' ' . join(files)

call ack#Ack(a:cmd, args)
endfunction "}}}

function! ack#ShowResults() "{{{
let l:handler = s:UsingLocList() ? g:ack_lhandler : g:ack_qhandler
execute l:handler
Expand Down
9 changes: 9 additions & 0 deletions doc/ack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ shows the results in a split window.
Just like |:AckAdd| but instead of the |quickfix| list, matches are added
to the current |location-list|

:AckBuffers[!] [options] {pattern} *:AckBuffers*

Search all listed buffers files for the {pattern}.

:LAckBuffers [options] {pattern} *:LAckBuffers*

Just like |:AckBuffers| but instead of the |quickfix| list, matches are
placed in the current |location-list|.

:AckFile [options] {pattern} [{directory}] *:AckFile*

Search recursively in {directory} (which defaults to the current
Expand Down
2 changes: 2 additions & 0 deletions plugin/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ command! -bang -nargs=* -complete=file AckAdd call ack#Ack('grepadd<bang>
command! -bang -nargs=* -complete=file AckFromSearch call ack#AckFromSearch('grep<bang>', <q-args>)
command! -bang -nargs=* -complete=file LAck call ack#Ack('lgrep<bang>', <q-args>)
command! -bang -nargs=* -complete=file LAckAdd call ack#Ack('lgrepadd<bang>', <q-args>)
command! -bang -nargs=* AckBuffers call ack#AckBuffers('grep<bang>', <q-args>)
command! -bang -nargs=* LAckBuffers call ack#AckBuffers('lgrep<bang>', <q-args>)
command! -bang -nargs=* -complete=file AckFile call ack#Ack('grep<bang> -g', <q-args>)
command! -bang -nargs=* -complete=help AckHelp call ack#AckHelp('grep<bang>', <q-args>)
command! -bang -nargs=* -complete=help LAckHelp call ack#AckHelp('lgrep<bang>', <q-args>)
Expand Down