Friday, October 20, 2017

Re: Directing which window is changed with :copen

On Friday, October 20, 2017 at 9:24:50 PM UTC-5, Tim Chase wrote:
> On 2017-10-20 21:04, Tim Chase wrote:
> > Long a nagging annoyance, I figured it's time to ask. I frequently
> > will do a :vimgrep on a term under the cursor, but want the
> > resulting navigation to open in a new window.
>
> Digging a little further, it's not quite as capricious/malicious as
> I'd thought. The help does state that it will open in the window
> immediately above the quickfix window. It just usually happens that
> the window I want to preserve is in that position at the bottom of
> my window-stack. I did also encounter ^W_<Enter> which seems to solve
> most of my problems. Though it would be nice to be able to choose
> which window the default <Enter> tromped.
>
> -tim

Oh. I guess I have a mapping to do what I described, the built-in behavior is as you say.

Put something like this in ~/.vim/after/ftplugin/qf.vim:

nnoremap <silent> <buffer> <CR> :call QfEnter()<CR>zv

function! QfEnter()
let l:lnum = line('.')
if b:errorlist_type == 'location'
let l:cmd = 'll'
else
let l:cmd = 'cc'
endif
wincmd p
exe l:cmd l:lnum
endfunction

I apparently have an old version of Vim (7.4.657) and old config to match, so my method of setting b:errorlist_type won't work in the latest Vim. There was a thread recently on how to find this information in Vim 8.0 but hopefully the above gives you the general approach.

--
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment