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.
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