ag,vim and the quickfix window

439 views
Skip to first unread message

Matteo Cavalleri

unread,
Dec 23, 2013, 6:04:14 AM12/23/13
to vim...@googlegroups.com
I'm trying to integrate ag in my workflow, i.e. stop switching to a shell to grep and then going back to vim ;)

I first started to simply use :Ggrep (from fugitive) but the "press enter to continue" message made me add another plugin to my vimrc, so I'm now trying to use ag.vim

there's one thing though that confuses me a bit... I've configured vim to automatically fold php files when i load them. when I press <cr> in the quickfix window, vim loads the file and unfold the code as needed to show the line I've jumped to, and that's fine. however if i presso "o" or "go" (two maps defined by the plugin), vim loads the file but doesn't unfold the code. given the fact that "o" is simply defined as:

nnoremap <silent> <buffer> o <CR>

i don't understand why there's no unfolding here...

Josh

unread,
Dec 23, 2013, 11:01:01 AM12/23/13
to vim...@googlegroups.com, vim...@googlegroups.com
Yeah that's a little strange. I've added an issue about this here: https://github.com/rking/ag.vim/issues/33 . Also it might be nice to have an option to close folds when opening matches (though I don't think that'd be the default), so I've added that as a feature request up for discussion here: https://GitHub.com/rking/ag.vim/issues/34 .

Thanks for the report!


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Benji Fisher

unread,
Dec 23, 2013, 1:11:04 PM12/23/13
to vim...@googlegroups.com
On Mon, Dec 23, 2013 at 11:01 AM, Josh <random...@gmail.com> wrote:

On Dec 23, 2013, at 5:04 AM, Matteo Cavalleri <cvl...@gmail.com> wrote:

I'm trying to integrate ag in my workflow, i.e. stop switching to a shell to grep and then going back to vim ;)

I first started to simply use :Ggrep (from fugitive) but the "press enter to continue" message made me add another plugin to my vimrc, so I'm now trying to use ag.vim

there's one thing though that confuses me a bit... I've configured vim to automatically fold php files when i load them. when I press <cr> in the quickfix window, vim loads the file and unfold the code as needed to show the line I've jumped to, and that's fine. however if i presso "o" or "go" (two maps defined by the plugin), vim loads the file but doesn't unfold the code. given the fact that "o" is simply defined as:

nnoremap <silent> <buffer> o  <CR>

i don't understand why there's no unfolding here...

Yeah that's a little strange. I've added an issue about this here: https://github.com/rking/ag.vim/issues/33 . Also it might be nice to have an option to close folds when opening matches (though I don't think that'd be the default), so I've added that as a feature request up for discussion here: https://GitHub.com/rking/ag.vim/issues/34 .

Thanks for the report!

     Maybe it has to do with how you have configured the automatic folding of PHP files.  Is it done by mapping <CR> in the quickfix window? Try

:map <CR>

from the quickfix window.  If there is a mapping, then it will not be triggered by the :nnoremap (emphasis on the "nore").

     If that is not the answer, you could try

:9verbose normal ^M
:9verbose normal o

(where ^M means a literal <CR>:  enter with <C-V><CR>).

HTH
-- 
Benji Fisher

Matteo Cavalleri

unread,
Dec 23, 2013, 1:43:11 PM12/23/13
to vim...@googlegroups.com
>
>      Maybe it has to do with how you have configured the automatic folding of PHP files.  Is it done by mapping <CR> in the quickfix window? Try
>

map <cr> reports just two maps for visual mode set by easyalign, and in any case automatic folding should be triggered by standard vim settings (nothing fancy for php, i get folds on other file types as well)


>      If that is not the answer, you could try
>
> :9verbose normal ^M
> :9verbose normal o

they both gives some output, but it's not easy to compare them, because as soon as i click to select the text (to copy and past it) it disappears


Ben Fritz

unread,
Dec 23, 2013, 1:53:11 PM12/23/13
to vim...@googlegroups.com

There's no unfolding here because the 'foldopen' option controls which actions open folds. Although this option includes "quickfix" by default, this option is also ignored when inside a mapping. From the help:

*'foldopen'* *'fdo'*
'foldopen' 'fdo' string (default: "block,hor,mark,percent,quickfix,
search,tag,undo")
global
{not in Vi}
{not available when compiled without the |+folding|
feature}
Specifies for which type of commands folds will be opened, if the
command moves the cursor into a closed fold. It is a comma separated
list of items.
NOTE: When the command is part of a mapping this option is not used.
Add the |zv| command to the mapping to get the same effect.

Matteo Cavalleri

unread,
Dec 23, 2013, 5:05:40 PM12/23/13
to vim...@googlegroups.com

> There's no unfolding here because the 'foldopen' option controls which actions open folds. Although this option includes "quickfix" by default, this option is also ignored when inside a mapping. From the help:

ah! mistery solved. thanks. there's so much stuff in vim that even diving in the documentation requires a lot of training :p

anyway ag.vim mappings are not configurable, and i already wanted to change them a bit, so I followed the augroup suggestion given here in another thread and "wrote" my own mappings, which indeed included 'zvzz'

thanks for the help guys

Tony Mechelynck

unread,
Dec 23, 2013, 5:36:37 PM12/23/13
to vim...@googlegroups.com
On 23/12/13 23:05, Matteo Cavalleri wrote:
[...]
> ah! mistery solved. thanks. there's so much stuff in vim that even diving in the documentation requires a lot of training :p

Yeah, there's that "needle-in-a-haystack" feeling. Happily, even for
that, there is help. Read it when you have the time to concentrate on
the contents (or, contrariwise, when you're so pressed that you can't do
anything else until you find the answer).

See:
:help (or <F1>)
:help online-help

[...]
>
> thanks for the help guys
>
NP

Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
54. You start tilting your head sideways to smile.

Matteo Cavalleri

unread,
Dec 24, 2013, 2:54:55 AM12/24/13
to vim...@googlegroups.com
> Yeah, there's that "needle-in-a-haystack" feeling. Happily, even for
>
> that, there is help. Read it when you have the time to concentrate on

I've started to read it, but sometimes the problem is not searching, but knowing what you are looking for. I would have probably read everything about key maps, but an option to control fold opening... I think I could have never thought of that :)

Tony Mechelynck

unread,
Dec 24, 2013, 3:30:29 AM12/24/13
to vim...@googlegroups.com
When you're groping in the dark, and ":help {subject}" doesn't bring up
anything relevant, the :helpgrep command is a great thing to have — it
will search the whole text of the help files for any search pattern you
can think up (and IIRC, historically Vim got it in one version, and
:vimgrep only in the next one: that shows how much it was needed).

BTW, if you can afford to reserve three F keys, here are some mappings
which can help for the whole family of quickfix commands (including
:helpgrep, :vimgrep, :grep, :make, the :cscope searches for which
'cscopequickfix' is set…):

:map <F2> :cnext<CR>
:map <S-F2> :cprev<CR>
:map <F3> :cnfile<CR>
:map <S-F3> :cpfile<CR>
:map <F4> :cfirst<CR>
:map <S-F4> :clast<CR>

For :make you may want to set 'autowrite' or 'autowriteall' to get
auto-save of any corrections you make in the source.

Best regards,
Tony.
--
The person who marries for money usually earns every penny of it.

Reply all
Reply to author
Forward
0 new messages