ag.vim
ag.vim copied to clipboard
Opens file in unexpected split
When I run :Ag
while focused on a split, I expect a result to be opened in that same split. However, it seems to pick a split at random, which is kind of disruptive.
:Ag
opens the quickfix window (:LAg
opens the location list). These might open in strange spots depending on what you (or other plugins) have set 'splitbelow' or 'splitright' to.
Sorry, I don't think I explained this so well. The quick fix window opens in the correct position (the bottom of the current window). The issue I'm having is when I already have several splits open. The cursor will be focused on one of these splits.
When I run :Ag <search term>
, here's what I expect to happen:
- Ag.vim opens a quickfix window on the bottom of the current window.
- Nothing else happens until I pick a file.
- When I pick a file, it's opened in the last split I was focused on.
What actually happens (bold doesn't match my expectations):
- Ag.vim opens a quickfix window on the bottom of the current window.
- Ag.vim opens the first result in the last split I was focused on.
- When I pick a file, it's opened in a seemingly random split that already existed.
When I run :LAg <search term>
, I expect the same behavior as :Ag <search term>
, except in a location list instead of a quickfix window. But here's what happens (bold again for an expectation mismatch):
- Ag.vim opens a location list on the bottom of the current window.
- Ag.vim opens the first result in the last split I was focused on.
- When I pick a file, it's opened in the last split I was focused on.
Hmm... ag.vim uses :grep
internally. Do you mind doing some tests using :grep
(you might need to do :copen
manually after searching) with split windows and see if you get the same results?
We only try to force where things are opened when you're using the mappings this plugin provides (and, if you look at the issues list, some of those have existing bugs).
When I used :grep
, I did have to use :copen
to show the Quickfix window. I had to prefix it with botright
to get it to open in the same position that :Ag
opens it. It seems to be displaying the same behavior that I reported.
That makes sense. You could use :Ag! Too avoid jumping to matches right after searching, then one if the mappings (see :h ag) as a workaround.
Other than that we could try to force it to open splits in a more predictable way, but inertial commands should be predictable. I'll look into the :grep docs to see if I can figure anything out.
@exchgr, Did you find a solution for this? I'm experiencing the same issue as you did. Mine opens in a new tab. Unfortunately, I can't find a setting for it on the docs.
@cumbreras Nope. I've mostly stopped using this plugin because of this issue.
@exchgr What a shame. Thanks for letting me know :+1:
Hmm, what if you tried adding:
let g:ag_qhandler="copen"
let g:ag_lhandler="lopen"
to your vimrc? I can't recall why these variables were created, but I think they've been there since this plugin was forked from ack.vim. If this works, maybe it's time to change the defaults.
Is there any workaround for stopping the selection of the first result in the search and opening that file? The way it's currently configured, you have to open a new tab to not lose your current working file.
I see Ag!
seems to work for not opening the first result. Can we set this as default in options somehow?
I just tried getting this to work again, and I had some success jumping off @losingkeys's suggestion. Here's how I matched my expectations as outlined in my comment on Feb 13:
In vimrc:
let g:ag_lhandler="botright lopen"
Then, running :LAg! <search-query>
behaves as expected.
@typeoneerror Mind opening an issue for this option? I thought about it before... but it seemed like it was going against vim's convention, but if people will use it I'm not opposed to adding it.
@exchgr strange. Does
let g:ag_lhandler="lopen"
Work? The botright
part is just so new windows open in the bottom/right part of vim. If we're reusing windows it shouldn't be necessary. I'll have to look up why vim's resuing windows here and why ag.vim defaults options to having "botright" in them, it doesn't seem (to me) like a good default.
let g:ag_lhandler="lopen"
works, but it opens a split under the current window. That's fine, but I was just trying to mimic the default behavior somewhat. Without either of those options, Ag
opens a quickfix window on the bottom right. That also happens to be my preference.
@exchgr is this no longer an issue then? Sorry for the delay, I'm just now going through the issues again. A quick scan of this one looks like you have it working how you want, but we/I should make sure this plugin respects options like splitbelow
and splitright
and maybe change the g:ag_*handler
options to default to whatever those are (e.g. remove any :vertical
or :botright
prefixes from them).
@losingkeys What are you saying, change the default behavior (or add the ability to do so from a .vimrc
) if the plugin respects those options?
I'm saying maybe change this plugin's default behavior if it overrides vim's default, to avoid surprises.