Automatically Closing Syntastic Error Window when Switching Vim Windows

217 views
Skip to first unread message

Richard Merry

unread,
Aug 24, 2016, 3:56:00 AM8/24/16
to vim-syntastic
Hello,
I often work with multiple windows open in Vim; typically at least a vertical split. One issue that I sometime see is my left window will also have a Syntastic error window open at the bottom, reporting errors as expected. I will then move to the right window to do some work there; leaving me with two windows on the left: the main file buffer window and the lower Syntastic error windows; and the current window with focus on the right. When I now move to the left window again, with <C-w> h, focus will be given to the Syntastic error window and not the actual window on to the buffer I have open. 

I fully recognise this is expected behaviour if for example I move down to the Syntastic error window before moving right. The issue is that moving left directly into the Syntastic error window has never once been my desired behaviour.

One solution would be to have the Syntastic error window close automatically upon moving away from the window that it is reporting on. Is there anyway to do this out of the box or will I have to get my VimL on?

Kind regards,
Rich

LCD 47

unread,
Aug 24, 2016, 5:26:02 AM8/24/16
to vim-syntastic
On 24 August 2016, Richard Merry <rme...@gmail.com> wrote:
> Hello,
> I often work with multiple windows open in Vim; typically at least
> a vertical split. One issue that I sometime see is my left window
> will also have a Syntastic error window open at the bottom, reporting
> errors as expected. I will then move to the right window to do some
> work there; leaving me with two windows on the left: the main file
> buffer window and the lower Syntastic error windows; and the current
> window with focus on the right. When I now move to the left window
> again, with <C-w> h, focus will be given to the Syntastic error window
> and not the actual window on to the buffer I have open.
>
> I fully recognise this is expected behaviour if for example I move
> down to the Syntastic error window before moving right. The issue is
> that moving left directly into the Syntastic error window has never
> once been my desired behaviour.

I'm not sure I understand why you think this can (or should) be
somehow fixed by syntastic. With <C-w>h the focus moves to the window
that is to the left on the cursor's line. According to the manual:

: CTRL-W h Move cursor to Nth window left of current one. Uses the
: cursor position to select between alternatives.

That is, start near the bottom of your right split and you'll land
on syntastic's error window. Start with the cursor higher up, and
you'll land to your left split. This is basic window navigation that
has nothing to do with syntastic.

> One solution would be to have the Syntastic error window close
> automatically upon moving away from the window that it is reporting
> on. Is there anyway to do this out of the box or will I have to get my
> VimL on?

You could try to run lclose (or perhaps SyntasticReset) from a
WinLeave autocmd. But you'd have to be careful not to do that when
you're leaving syntastic's error window, otherwise you wou;dn't be able
to keep the error window open. It isn't trivial, and it's even less
trivial keeping it from breaking other things. Window handling in Vim
is insanely fragile, and the API is less than helpful.

/lcd

Richard Merry

unread,
Aug 24, 2016, 5:35:03 AM8/24/16
to vim-syntastic
>I'm not sure I understand why you think this can (or should) be
somehow fixed by syntastic.  
 
As I said, I understand that the behaviour is expected and correct; I was just wondering if anybody else had the same gripe as myself and had developed their own solution to it.

I appreciate your advice with regards to calling lclose from a WinLeave autocmd. I will look into implementing this and see how much mileage I get out of it.

Thanks for the help.

Vitchyr Pong

unread,
Jul 28, 2019, 1:59:59 PM7/28/19
to vim-syntastic
I came up with this solution so that whenever I change windows with ctrl+h/j/k/l, it first calls :lclose. I added this to my .vimrc:

map <c-h> :lclose<CR><c-w>h
map <c-j> :lclose<CR><c-w>j
map <c-k> :lclose<CR><c-w>k
map <c-l> :lclose<CR><c-w>l
Reply all
Reply to author
Forward
0 new messages