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

Opens file in unexpected split

Open exchgr opened this issue 9 years ago • 16 comments

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.

exchgr avatar Feb 12 '15 19:02 exchgr

: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.

losingkeys avatar Feb 13 '15 00:02 losingkeys

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:

  1. Ag.vim opens a quickfix window on the bottom of the current window.
  2. Nothing else happens until I pick a file.
  3. 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):

  1. Ag.vim opens a quickfix window on the bottom of the current window.
  2. Ag.vim opens the first result in the last split I was focused on.
  3. 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):

  1. Ag.vim opens a location list on the bottom of the current window.
  2. Ag.vim opens the first result in the last split I was focused on.
  3. When I pick a file, it's opened in the last split I was focused on.

exchgr avatar Feb 13 '15 17:02 exchgr

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).

losingkeys avatar Feb 14 '15 17:02 losingkeys

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.

exchgr avatar Feb 17 '15 04:02 exchgr

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.

losingkeys avatar Feb 17 '15 12:02 losingkeys

@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 avatar Oct 20 '15 10:10 cumbreras

@cumbreras Nope. I've mostly stopped using this plugin because of this issue.

exchgr avatar Oct 20 '15 19:10 exchgr

@exchgr What a shame. Thanks for letting me know :+1:

cumbreras avatar Oct 20 '15 20:10 cumbreras

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.

losingkeys avatar Oct 21 '15 23:10 losingkeys

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?

typeoneerror avatar Oct 23 '15 18:10 typeoneerror

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.

exchgr avatar Oct 26 '15 20:10 exchgr

@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.

losingkeys avatar Oct 28 '15 22:10 losingkeys

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 avatar Oct 28 '15 22:10 exchgr

@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 splitrightand maybe change the g:ag_*handler options to default to whatever those are (e.g. remove any :vertical or :botright prefixes from them).

losingkeys avatar Feb 13 '16 02:02 losingkeys

@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?

exchgr avatar Feb 13 '16 07:02 exchgr

I'm saying maybe change this plugin's default behavior if it overrides vim's default, to avoid surprises.

losingkeys avatar Feb 13 '16 14:02 losingkeys