Skip to content

Commit

Permalink
Add ability to search all open buffers
Browse files Browse the repository at this point in the history
Closes #189
  • Loading branch information
versi786 committed Nov 13, 2020
1 parent 36e40f9 commit 66e54c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions autoload/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,23 @@ 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 != ""')

" 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

0 comments on commit 66e54c6

Please sign in to comment.