Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toggle Error Location panel in syntastic

Tags:

vim

syntastic

How can I set a keyboard shortcut to toggle Syntastic Error Location List Panel in vim.

:Errors - Shows Location Panel

:lclose - Hides the Location Panel

I'm very new to VimScript, if there would be a way to check visibility of the Location List Panel. This should be fairly easy to do.

like image 351
system64 Avatar asked Jul 07 '13 13:07

system64


2 Answers

I do not know how to differentiate* quickfix and location lists, but in place of checking whether location list is displayed I would suggest just closing it and checking whether number of windows shown has changed:

function! ToggleErrors()
    let old_last_winnr = winnr('$')
    lclose
    if old_last_winnr == winnr('$')
        " Nothing was closed, open syntastic error location panel
        Errors
    endif
endfunction

* if you are fine with the solution that will try lclose if any is active check for the buffer displayed with buftype quickfix:

function! ToggleErrors()
    if empty(filter(tabpagebuflist(), 'getbufvar(v:val, "&buftype") is# "quickfix"'))
         " No location/quickfix list shown, open syntastic error location panel
         Errors
    else
        lclose
    endif
endfunction

. Note that lclose will not close quickfix list.

To toggle the Error Panel with Ctrl-e you can use the following mapping

nnoremap <silent> <C-e> :<C-u>call ToggleErrors()<CR>
like image 71
ZyX Avatar answered Oct 18 '22 02:10

ZyX


According to Syntastic help, the command to close Syntastic error window is :

:SyntasticReset
like image 8
PokerFace Avatar answered Oct 18 '22 03:10

PokerFace