Skip to content

Commit

Permalink
Port AgBuffer to AckBuffer
Browse files Browse the repository at this point in the history
Now you can search in opened buffers instead of some hacky bufdo
  • Loading branch information
zatnas committed Nov 6, 2020
1 parent 36e40f9 commit 9787255
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions autoload/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ function! ack#AckHelp(cmd, args) "{{{
call ack#Ack(a:cmd, args)
endfunction "}}}

function! ack#AckBuffer(cmd, args) "{{{
let l:bufs = filter(range(1, bufnr('$')), 'buflisted(v:val)')
let l:files = []
for buf in l:bufs
let l:file = shellescape(fnamemodify(bufname(buf), ':p'))
if !isdirectory(l:file)
call add(l:files, l:file)
endif
endfor
call ack#Ack(a:cmd, a:args . ' ' . join(l:files, ' '))
endfunction "}}}

function! ack#AckWindow(cmd, args) "{{{
let files = tabpagebuflist()

Expand Down
11 changes: 11 additions & 0 deletions doc/ack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ shows the results in a split window.
will open the |Quickfix| window for you. If [!] is not given the first
occurrence is jumped to.

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

Search for {pattern} in all open buffers. Behaves just like the |:grep|
command, but will open the |QuickFix| window for you. If [!] is not given
the first error is jumped to.

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

Just like |:Ack|, but instead of making a new list, the matches are
Expand All @@ -36,6 +42,11 @@ shows the results in a split window.
Just like |:Ack| but instead of the |quickfix| list, matches are placed in
the current |location-list|.

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

Just like |:AckBuffer| but instead of the |quickfix| list, matches are
added to the current |location-list|

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

Just like |:AckAdd| but instead of the |quickfix| list, matches are added
Expand Down
2 changes: 2 additions & 0 deletions plugin/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ if !exists("g:ack_use_cword_for_empty_search")
endif

command! -bang -nargs=* -complete=file Ack call ack#Ack('grep<bang>', <q-args>)
command! -bang -nargs=* -complete=file AckBuffer call ack#AckBuffer('grep<bang>', <q-args>)
command! -bang -nargs=* -complete=file AckAdd call ack#Ack('grepadd<bang>', <q-args>)
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 LAckBuffer call ack#AckBuffer('lgrep<bang>', <q-args>)
command! -bang -nargs=* -complete=file LAckAdd call ack#Ack('lgrepadd<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>)
Expand Down

0 comments on commit 9787255

Please sign in to comment.