26

enter image description here

I use eslint with ale to lint my Javascript code. After editing a code block, I often have a few errors to fix. Fixing is done by navigating to the next erroneous line, reading the problem from the ruler and fixing.

If I could skip the navigation phase and use a specific key binding to navigate to the location of the next error - its line, and hopefully its column - it would be great.

Is there a way to use key binding to navigate to the next lint/ale error?

2 Answers 2

38

ALE has many commands that can navigate linting errors, and :ALENext works great for this operation. By default, ALE maps no bindings, I assume to allow for non-clashing customization.

In your ~/.vimrc (or ~/.config/nvim/init.vim for NeoVim), I use:

nmap <silent> <leader>aj :ALENext<cr>
nmap <silent> <leader>ak :ALEPrevious<cr>

Leader is \ by default

1
  • 3
    Maybe worth adding that if you want to jump specifically to errors or warnings, that (verbatim from the docs): "-error, -warning and -info enable jumping to errors, warnings or infos respectively, ignoring anything else. They are mutually exclusive and if several are provided the priority is the following: error > warning > info."
    – Harry
    Commented Mar 25, 2019 at 17:44
15

You can easily move between errors by adding some key bindings to ale's <Plug> mappings (see :h <Plug>).

In this example use Ctrl+j to go to next error and Ctrl+k to go to the previous error.

nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)
2
  • 1
    This assumes that you have Plug rather than Vundle or Pathogen installed.
    – icc97
    Commented Nov 25, 2018 at 16:36
  • This appears to come direct from the ALE repo README: github.com/w0rp/…
    – icc97
    Commented Nov 25, 2018 at 19:55

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.