Skip to content

Commit

Permalink
Add option to disable blank searches
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshbala committed Apr 14, 2016
1 parent b9ceb0f commit 20772f4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions autoload/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ function! ack#Ack(cmd, args) "{{{
let l:grepformat = '%f'
endif

" Check user policy for blank searches
if empty(a:args)
if !g:ack_use_cword_for_empty_search
echo "No regular expression found."
return
endif
endif

" If no pattern is provided, search for the word under the cursor
let l:grepargs = empty(a:args) ? expand("<cword>") : a:args . join(a:000, ' ')

Expand Down
16 changes: 16 additions & 0 deletions doc/ack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ Example:
let g:ack_use_dispatch = 1
<

*g:ack_use_cword_for_empty_search*

g:ack_use_cword_for_empty_search
Default: 1

Use this option to enable blank searches to run against the word under the
cursor. When this option is not set, blank searches will only output an error
message.


Example:
>
let g:ack_use_cword_for_empty_search = 0
<


==============================================================================
MAPPINGS *ack-mappings*

Expand Down
4 changes: 4 additions & 0 deletions plugin/ack.vim
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ if !exists("g:ack_autofold_results")
let g:ack_autofold_results = 0
endif

if !exists("g:ack_use_cword_for_empty_search")
let g:ack_use_cword_for_empty_search = 1
endif

command! -bang -nargs=* -complete=file Ack call ack#Ack('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>)
Expand Down

0 comments on commit 20772f4

Please sign in to comment.