Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to populate the quickfix list or location list of Vim/Neovim with arbitrary linter output?

Say I just ran a linter in the terminal and I have a bunch of linter output in the standard format:

path/to/some/file.foo:45:23: This is an error message
path/to/some/file.foo:46:12: This is another error message
...

I am currently opening each file manually in Neovim, navigating to the correct line and fixing the issue.

Instead, I want to populate the quickfix or location list in Vim or Neovim with this information so I can quickly jump to each spot and fix the error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What would be the simplest/quickest way to achieve this?

>Solution :

That’s what the :help -q command-line flag is for:

$ vim -q filewitherrors

You can redirect the output of your linter to a file and then pass that file to Vim’s -q:

$ yourlinter file.foo > filewitherrors
$ vim -q filewitherrors

If your shell allows it, you can use process substitution to remove intermediary steps and ghost files:

$ vim -q <(yourlinter)

Or, if you already ran your linter and forgot to pass it to Vim, you can re-run it and pass it to Vim via process substitution:

$ vim -q <(!!)

Since this is a situation I often find myself in, I added this command to my bash config years ago:

# open Vim with output of last command in quickfix
vimq() {
    vim -q <($(fc -nl -1))
}

which allows me to do:

$ yourlinter file.foo
(output of linter)
$ vimq

NOTE: fc -nl -1 is a more portable—therefore preferable in a scripting context—way to recall the last command than !!. See $ man fc.

NOTE: you only mentioned the quickfix list in your question but, if you also want the quickfix window, you can add one more item to the command: :help :cwindow.

$ vim -q <(!!) +cw
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading