Use Vale on Neovim
Vale is a command-line tool that brings code-like linting to prose. Very fast and works well with markup.
Update: June 26th 2022, Use nvim-lint.
To use Vale with Neovim you will need to be able to run vale, process, and show the errors. A few plugins that can support this nvim-lint (builtin support), ale. As well as LSP servers EFM-langserver or null-ls.
I personally went with the LSP option as I handle most of my formatting and linting through it.
Vale and Error Format
To do this we use the output from vale --output=line
. This outputs a line for each error.
/home/rockerboo/code/davelage/content/use-vale-on-neovim.md:9:105:[write-good.Weasel] 'few' is a weasel word!
Formatted as
Path:Line:Column:Message
…and using the vim errorformat
we can extract this. See :h errorformat
in Neovim for more details on this formatting system.
%f:%l:%c:%m
You are able to set the format inside your linter of choice.
If you, like me, want to also have a severity, (error, warning, notice) then you’ll need to use a go template for making a custom output. Here is a simple example with Severity. You want to put this file somewhere in your user files since you want to use it for every project. I choose ~/.config/vale/output.tmpl
.
{{- /* Very much like `vale --output=line`, but with the severities too! -}}
{{- /* See also https://docs.errata.ai/vale/cli#template-examples */ -}}
{{- /* https://github.com/errata-ai/vale/issues/350 */ -}}
{{- range .Files}}
{{- $p := .Path -}}
{{- range .Alerts -}}
{{- printf "%s:%d:%d:%s:[%s] %s" $p .Line (index .Span 0) .Severity .Check .Message }}
{{end -}}
{{end}}
This gives us this format with the severity
/home/rockerboo/code/davelage/content/posts/use-vale-on-neovim.md:39:251:warning:[Google.Will] Avoid using 'will'.
Integration
And then, I put it all together using EFM-langserver. This is part of the yaml config. EFM-langserver allows use of the vim.diagnostic
API’s to interact with these alerts/errors.
vale: &vale
lint-command: 'vale --output=/home/rockerboo/.config/vale/output.tmpl '
lint-ignore-exit-code: true
lint-formats:
- '%f:%l:%c:%trror:%m'
- '%f:%l:%c:%tarning:%m'
require-marker: true
root-markers:
- '.vale.ini'
Update
June 26th 2022
I would now suggest nvim-lint as it has Vale configured already. You won’t need to configure a general purpose LSP client to run it. Uses the newer vim.diagnostic
which works well with your other LSP connections.