Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight search only highlights results in first file opened #55

Closed
mario-grgic opened this issue Mar 29, 2014 · 8 comments
Closed

Highlight search only highlights results in first file opened #55

mario-grgic opened this issue Mar 29, 2014 · 8 comments

Comments

@mario-grgic
Copy link

When you have g:aghihghlight=1 in your .vimrc and perform :Ag findstring, findstring is highlighted only in first opened file. If you navigate to the next search result from the quickfix window (or with :cnext/:cprevious) findstring is no longer highlighted.

The following patch fixes this:

--- autoload/ag.vim 2014-03-27 23:30:46.000000000 -0400
+++ autoload/ag.vim.patched 2014-03-29 14:25:27.000000000 -0400
@@ -71,6 +71,7 @@
if exists("g:aghighlight")
let @/=a:args
set hlsearch

  • call feedkeys(":let &hlsearch=1", "n")
    end

redraw!

@fanchangyong
Copy link

I encountered the same problem in my cli version vim,but my MacVim is good.

@fanchangyong
Copy link

@mario-grgic Thank you for your awesome solution, it solved the problem,but ,in my version I have to use the following command:

call feedkeys(":let &hlsearch=1", "n")

added a "" before "CR"

Thank you.

@Numkil
Copy link

Numkil commented Jun 10, 2015

Try this please. Tell me how it performs for both of you.

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

This is how it's done in ack.vim

@fanchangyong
Copy link

@Numkil

Error detected while processing function ag#Ag:
line   66:
E121: Undefined variable: s:args
E116: Invalid arguments for function matchstr(s:args, "\\v(-)\@<!(\<)\@<=\\w+|['\"]\\zs.{-}\\ze['\"]")
E15: Invalid expression: matchstr(s:args, "\\v(-)\@<!(\<)\@<=\\w+|['\"]\\zs.{-}\\ze['\"]")

@Numkil
Copy link

Numkil commented Jun 11, 2015

Sorry that is a copy paste error on my behalf, ofcourse it needs to be a:args in ag.vim

@fanchangyong
Copy link

@Numkil
It works,thank you.

@Numkil
Copy link

Numkil commented Jun 11, 2015

I'll make a small pull request for this, I think it's a good idea to keep as much code in common with ack.vim so we can benefit from their work as well and maybe bugs will be found earlier. 👍

losingkeys added a commit that referenced this issue Jul 9, 2015
fix #55, use ack.vim's solution for highlighting the search word
@hunhejj
Copy link

hunhejj commented Jul 19, 2016

I frequently switch back and forth between working_path_mode-s and I would normally do this by typing ":let" and then choosing the most recently used let command. However because of this highlighting trick the first result is always ":let &hlsearch=1 (...)" instead of what I await.
@Numkil any ideas, how to get rid of this behaviour?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants