Syntastic: Shortcut for toggle location list

Created on 4 Feb 2012  路  7Comments  路  Source: vim-syntastic/syntastic

Please add a new command, something like :ToggleErrors, so people can map a key to open/close the Location window.

Most helpful comment

Just a quick snippet I put together for future references. Someone might find it useful. I wanted to have a Toggle Button to open and close the location list and managed to get it working like this

    map <F8> <ESC>:call SyntasticToggle()<CR>

    let g:syntastic_is_open = 0  
    function! SyntasticToggle()
    if g:syntastic_is_open == 1
        lclose
        let g:syntastic_is_open = 0 
    else
        Errors
        let g:syntastic_is_open = 1 
    endif
    endfunction

This way my location list open and closes everytime I press F8 in Normal Mode.

All 7 comments

Why?
Simply map :lclose and :lopen.

Oh, so simple! Didn't know about lclose and lopen. Thanks

You may also want to check tpope's unimpaired plugin.
It allows to fast jump between errors with ]l [l. I find it very handy.

Just a quick snippet I put together for future references. Someone might find it useful. I wanted to have a Toggle Button to open and close the location list and managed to get it working like this

    map <F8> <ESC>:call SyntasticToggle()<CR>

    let g:syntastic_is_open = 0  
    function! SyntasticToggle()
    if g:syntastic_is_open == 1
        lclose
        let g:syntastic_is_open = 0 
    else
        Errors
        let g:syntastic_is_open = 1 
    endif
    endfunction

This way my location list open and closes everytime I press F8 in Normal Mode.

Simply map :lclose and :lopen.

right, but that doesn't stop the location list from popping up on every save. Is there a way to disable that? I only want to be told how nonconformist I am when it's convenient for me

@arshbot: There is such a thing as a manual. You can save time (ours and yours) by reading it. To answer your question: :h :Errors, :h 'syntastic_auto_loc_list'.

To answer the question you should have asked: use ALE instead. It's maintained, it takes advantage of Vim 8 features, and it can do asynchronous checking.

Just a quick snippet I put together for future references. Someone might find it useful. I wanted to have a Toggle Button to open and close the location list and managed to get it working like this

    map <F8> <ESC>:call SyntasticToggle()<CR>

    let g:syntastic_is_open = 0  
    function! SyntasticToggle()
    if g:syntastic_is_open == 1
        lclose
        let g:syntastic_is_open = 0 
    else
        Errors
        let g:syntastic_is_open = 1 
    endif
    endfunction

This way my location list open and closes everytime I press F8 in Normal Mode.

Nice function to toggle the loc_list @macskay
The only problem that I saw with it is that if you have let g:syntastic_check_on_open = 1 and let g:syntastic_always_populate_loc_list = 1 and your file has errors or warnings when you open it the loc_list will show up automatically. When that happens and you press F8, this will not trigger the loc_list to disapear as you assigned 0 as the first value in your function. When you press F8 again, everything starts working fine. That is not a big issue but I decided to play with it a little and came up with the followingm, which toggles the loc_list every time.

map <F8> <ESC>:call SyntasticToggle()<CR>

function! SyntasticToggle()
  let g:wi = getloclist(2, {'winid' : 1})
  if g:wi != {}
    lclose
  else
    Errors
  endif
endfunction
Was this page helpful?
0 / 5 - 0 ratings