Skip to content

nvimdev/guard.nvim

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
doc
July 19, 2023 10:58
July 19, 2023 20:11
June 13, 2023 16:44
July 18, 2023 20:15
February 15, 2023 19:49
February 15, 2023 17:28
July 18, 2023 09:37

guard.nvim

Async formatting and linting utility for neovim.

Features

  • Blazingly fast
  • Async using coroutine and luv spawn
  • Builtin support for popular formatters and linters
  • Light-weight

Usage

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

ft('c'):fmt('tool-1')
       :append('tool-2')
       :lint('lint-tool-1')
       :append('lint-tool-2')

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
ft('c'):fmt('clang-format')
       :lint('clang-tidy')

-- use stylua to format lua files and no linter
ft('lua'):fmt('stylua')

-- use lsp to format first then use golines to format
ft('go'):fmt('lsp')
        :append('golines')
        :lint('golangci')

-- call setup LAST
require('guard').setup({
    -- the only option for the setup function
    fmt_on_save = true,
})

Use GuardFmt to manually call format, use GuardDisable to diable auto format. and you can create a keymap like

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

Builtin tools

Formatter

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

Table format for custom tool:

{
    cmd              --string tool command
    args             --table command arugments
    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
  • rubocop

Trobuleshooting

if guard does not auto format on save, run checkhealth first.

License MIT

About

async fast minimalist plugin make format easy in neovim

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages