mileszs / ack.vim

Vim plugin for the Perl module / CLI script 'ack'
Other
3.08k stars 396 forks source link

Search for selection #27

Closed martinklepsch closed 10 years ago

martinklepsch commented 13 years ago

Hey sometimes it would be really nice to be able to search for the current selection.

:Ack! '<,'>

At the moment this returns some errors:

 Error detected while processing function <SNR>19_Ack:
 E40: Can't open errorfile /var/folders/l8/1p3_btjs0y7bcw5k7df81czm0000gn/T/v9uVjcT/1

Maybe I am missing something here and this is already possible with some mapping. Just let me know then.

kassio commented 10 years ago

I have a workaround about it, basead on vim-visual-star-search:

function! VAckSearch()
  norm! gv"sy
  return ':Ack "' . EscapeAllString(@s) . '"'
endfunction

function! EscapeAllString(text)
  return substitute(escape(a:text, '*^$.?/\|{[()]}'), '\n', '\\n', 'g')
endfunction

vnoremap ,as :<C-u>exec VAckSearch()<CR>