Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jump to next error / code highlighted in red

When dealing with merge conflicts it is common that the >>>>>> and ====== inserted by DCVS are syntactically incorrect for the file I'm in and show up as highlighted in red. When dealing with merge conflicts it would be useful to have commands to jump to these error. When I type :cnext I just get the message "No Errors". These are Mercurial merge conflicts so I can't use Fugitive, but I generally prefer editing merge conflicts by hand anyway.

Is there a way to jump to the next syntax error in the file? I think these errors are dictated by the syntax highlighting file.

like image 794
Andy Ray Avatar asked Jun 15 '11 17:06

Andy Ray


2 Answers

You can use :lopen to open window containing error/warning lines. After that, navigate to each of them.

The actual answer is that you can use :lnext to jump to the next error, or :lprev, or ]l and [l (those are lowercase Ls) if you have vim-unimpaired, which you do, because you shouldn't use Vim without it.

This will not actually jump to the next red/error highlighted text group, but will jump to whatever your syntax plugin dictates is an error (and populates the location list). It is impossible in Vim to jump to a specific highlighting group, because no one has bothered to figure out how yet.

The plugin SRDispHiGrp comes close, but if you couldn't tell from the name, is too convulted and confusing for human use.

like image 172
Nguyen Avatar answered Nov 07 '22 19:11

Nguyen


I think you were on the right track with :cnext.

:cnext and :cprevious are Vim QuickFix commands; you can take advantage of them by using a code validation plugin that uses QuickFix mode, like pyflakes.vim for Python, and jslint.vim/jshint.vim for JavaScript.

This will result in syntax errors being marked with squiggly red underlines, as opposed to the solid red syntax error highlighting I believe you are seeing. You should then be able to use :cnext and :cprevious to skip to the next and previous marked errors.

like image 45
bryan Avatar answered Nov 07 '22 20:11

bryan