ack.vim icon indicating copy to clipboard operation
ack.vim copied to clipboard

no highlighting when searching with regrex

Open mboughaba opened this issue 7 years ago • 4 comments

Hi,

let g:ackhighlight = 1

When searching with regex, the matching searched term is not highlighted.

Ack! "TODO|FIXME|NOTE|HACK")

This is the code which is doing the highlighting

function! s:Highlight(args) "{{{
  if !g:ackhighlight
    return
  endif

  let @/ = matchstr(a:args, "\\v(-)\@<!(\<)\@<=\\w+|['\"]\\zs.{-}\\ze['\"]")
  call feedkeys(":let &hlsearch=1 \| echo \<CR>", "n")
endfunction "}}}

Have no idea how to start with that matchstr :rofl:

mboughaba avatar Oct 28 '17 21:10 mboughaba

Yeah the highlighting "support" is and might always be a hack, because of course ack's regex engine is entirely different from Vim's. If anyone has ideas on improving it though, I'm open to them. Maybe there's some portable-ish way to "pass through" match information better.

Might relate to #214.

ches avatar Nov 05 '17 13:11 ches

Hi @ches

Coming back to the same example:

Ack! "TODO|FIXME|NOTE|HACK"

It is possible to highlight all the matches simply by using vim's built-in hlsearch.

what I suggest

When searching using Ack we could set the highlighting in vim to match the exact pattern given to ack, in this case /\vFIXME\|TODO\|HACK\|NOTE. And of course we can always revert back to user's last search after that the quickfix is closed.

This behavior is to be enabled when g:ackhighlight = 1

What do you think? I am waiting for feedback to drop a PR.

Cheers, Mo.

mboughaba avatar Dec 06 '17 21:12 mboughaba

I don't think that's going to work because vim + ack's regexes are so very different.

petdance avatar Dec 06 '17 21:12 petdance

Why not borrow code from https://github.com/othree/eregex.vim/blob/master/plugin/eregex.vim? It has the E2v function to turn an extended Perl-Style regex to a Vim regex. See here

:echo E2v('^(foo|bar|2\d.*?0)$')
^\(foo\|bar\|2\d.\{-}0\)$

ubmarco avatar Dec 20 '19 09:12 ubmarco