guard.nvim #

Async formatting and linting utility for Neovim.

Features #

  • Blazingly fast
  • Async using coroutine and luv spawn
  • Built-in support for popular formatters and linters
  • Lightweight

Usage #

Use any plugin manager you like. Guard is configured in format like this:


If the tool is not supported, you will have to pass in a table instead of a string, see here for some examples, more info below.

local ft = require('guard.filetype')

-- use clang-format and clang-tidy for C files

-- use stylua to format lua files and no linter

-- use lsp to format first then use golines to format

-- call setup LAST
    -- the only option for the setup function
    fmt_on_save = true,

Use GuardFmt to manually call format, use GuardDisable to disable auto format. And you can create a keymap like this:

vim.keymap.set({'n','v'}, '<cmd>GuardFmt<CR>')

Built-in Tools #

Formatter #

  • lsp use vim.lsp.buf.format
  • clang-format
  • prettier
  • rustfmt
  • stylua
  • golines
  • black

Table format for custom tool:

    cmd            -- string tool command
    args           -- table command arguments
    fname          -- string insert filename to args tail
    stdin          -- boolean pass buffer contents into stdin
    timeout        -- integer
    ignore_pattern -- table ignore run format when pattern match
    ignore_error   -- when has LSP error ignore format

    -- special
    fn -- function if fn is set other field will not take effect

Linter #

  • clang-tidy
  • Pylint

Troubleshooting #

If Guard does not auto format on save, run checkhealth first.

License #

Licensed under the MIT license.