29

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.

2 Answers 2

25

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>
3
  • How do you see the quickfix panel? Not sure if the docs mention about it.
    – system64
    Commented Jul 7, 2013 at 20:33
  • 1
    @AkshayAurora :vimgrep, :grep, :make and so on all use quickfix list. :copen will show it. Docs do mention this, :vimgrep is the example in the second paragraph of :h quickfix. There are location list counterparts for all of these commands though: :lvimgrep, :lgrep, :lmake and so on.
    – ZyX
    Commented Jul 8, 2013 at 4:43
  • Thanks. However, when using gvim -p to edit multiple files, each time I move out and back to the tab, the location list reappears. Neither its visibility status nor its height is persistent. Anyway, I ended up setting g:syntastic_auto_loc_list to 0 and now I activate it manually so I don't mind.
    – Jérôme
    Commented Feb 17, 2016 at 14:25
8

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

:SyntasticReset
1
  • neatest solution.
    – markroxor
    Commented May 27, 2017 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.