Error location navigation in Vim Syntastic

10

2

I've got Syntastic installed in Vim and it is finding errors perfectly (mostly in Python code I'm working on). If I jump around normally in the file I see the errors in the status bar when the cursor is over a relevant line.

What I can't figure out is how to navigate directly between the errors.

I understand that syntastic is loading the errors into a Vim location list and I can make that appear with :lopen, switch to that window, choose a line and hit Enter and be taken to the main window on the right line.

What I would like to do though, is not have the list open, simply be editing away in the file with errors and hit a keyboard shortcut to skip to wherever the next warning/error is.

Is that possible? The docs suggest that :lNext and :lprevious are relevant, but they get me E553: No more items.

Chris Jones

Posted 2013-03-15T19:47:36.537

Reputation: 203

Answers

11

:lne[xt] and :lp[revious] are the correct shortcuts.

But :lN[ext] is not the same as :lne[xt]: it's an alternative to :lp[revious].

The message you get is due to the fact that these command don't wrap around when you reach the last or the first error.

The commands you listed in your question both jump to the previous error but chances are you are already on the first error and there's nothing before. use the right commands, keep in mind that they don't wrap around and you'll be good.

Read :h location-list for a complete list of commands.

romainl

Posted 2013-03-15T19:47:36.537

Reputation: 19 227

Is there a way to get them to wrap? – BallpointBen – 2018-07-29T04:01:49.067

No, there's no way to get them to wrap. There are various wrapper-based solutions in this thread and more in the form of plugins, though. My own plugin vim-qf has those. The implementation is here if you don't want a full-fledged plugin just for a couple mappings.

– romainl – 2018-07-29T09:04:54.693

5

If there's only one issue in the list, :ll will navigate to it.

Here's a fix for your .vimrc that will make keys mapped to :lnext and :lprev work correctly in the case of only one issue (by jumping to it). Change the nmappings at the end to your preferred key sequence.

(from https://github.com/scrooloose/syntastic/issues/32 )

" Fix syntastic error jumping
function! <SID>LocationPrevious()
  try
    lprev
  catch /^Vim\%((\a\+)\)\=:E553/
    llast
  endtry
endfunction

function! <SID>LocationNext()
  try
    lnext
  catch /^Vim\%((\a\+)\)\=:E553/
    lfirst
  endtry
endfunction

nnoremap <silent> <Plug>LocationPrevious    :<C-u>exe 'call <SID>LocationPrevious()'<CR>
nnoremap <silent> <Plug>LocationNext        :<C-u>exe 'call <SID>LocationNext()'<CR>
nmap <silent> e[  <Plug>LocationPrevious
nmap <silent> e]  <Plug>LocationNext

Greg Bell

Posted 2013-03-15T19:47:36.537

Reputation: 373

This is ugly if executed before the location list is first populated, or after population with no errors. See my answer for a fix.

– Tom Hale – 2016-09-25T09:52:13.450

4

Since :lnext etc. are tedious to type (you usually want to iterate quickly over them, the unimpaired.vim - Pairs of handy bracket mappings plugin provides (among others) short ]l mappings.

Ingo Karkat

Posted 2013-03-15T19:47:36.537

Reputation: 19 513

1

Written 30th October 2017

I would recommend installing vim-unimpaired plugin

This is also a great reference on the vim lists more generally.

Syntastic uses the locations list. Commands below (mappings marked with asterix come from the unimpaired.vim plugin mentioned above).

enter image description here

arcseldon

Posted 2013-03-15T19:47:36.537

Reputation: 111

0

Allow wrap-around from the first to the last error location (and vice versa):

" Allow :lprev to work with empty location list, or at first location
function! <SID>LocationPrevious()
  try
    lprev
  catch /:E553:/
    lfirst
  catch /:E\%(42\|776\):/
    echo "Location list empty"
  catch /.*/
    echo v:exception
  endtry
endfunction

" Allow :lnext to work with empty location list, or at last location
function! <SID>LocationNext()
  try
    lnext
  catch /:E553:/
    lfirst
  catch /:E\%(42\|776\):/
    echo "Location list empty"
  catch /.*/
    echo v:exception
  endtry
endfunction

This catches the following errors:

E42: No Errors
E776: No location list

And meekly says: Location list empty

(Credit to lcd074)

Tom Hale

Posted 2013-03-15T19:47:36.537

Reputation: 1 348

Actually, there is a less repetitive solution but it could do with the echo "Location list empty".

– Tom Hale – 2016-09-25T09:54:09.900

0

I think best way to use location list is to use combination Denite + unite-location plugin: https://github.com/chemzqm/unite-location

Arthur Sult

Posted 2013-03-15T19:47:36.537

Reputation: 101