GithubHelp home page GithubHelp logo

maximyurevich / guard.nvim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nvimdev/guard.nvim

0.0 0.0 0.0 121 KB

async fast minimalist plugin make format easy in neovim

License: MIT License

Lua 100.00%

guard.nvim's Introduction

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
  • Easy configuration for custom tools
  • Light-weight

Usage

Use any plugin manager you like. Guard is configured as follows:

local ft = require('guard.filetype')

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

-- Call setup() LAST!
require('guard').setup({
    -- the only options for the setup function
    fmt_on_save = true,
    -- Use lsp if no formatter was defined for this filetype
    lsp_as_default_formatter = false,
})
  • Use GuardFmt to manually call format, when there is a visual selection only the selection is formatted.
  • GuardDisable disables auto format for the current buffer, you can also GuardDisable 16 (the buffer number)
  • Use GuardEnable to re-enable auto format, usage is the same as GuardDisable

Example Configuration

Format c files with clang-format and lint with clang-tidy:

ft('c'):fmt('clang-format')
       :lint('clang-tidy')

Or use lsp to format go files first, then format with golines, then lint with golangci:

ft('go'):fmt('lsp')
        :append('golines')
        :lint('golangci')

Register multiple filetypes to a single linter or formatter:

ft('typescript,javascript,typescriptreact'):fmt('prettier')

Custom Configuration

Easily configure your custom formatter if not in the defaults:

{
    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     -- boolean: when has lsp error ignore format
    find             -- string: format if the file is found in the lsp root dir
    env              -- table: environment variables passed to cmd (key value pair)

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

For example, format your assembly with asmfmt:

ft('asm'):fmt({
    cmd = 'asmfmt',
    stdin = true
})

Consult the builtin tools if needed.

Supported Tools

Formatters

Linters

Troubleshooting

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

License MIT

guard.nvim's People

Contributors

barrett-ruth avatar erikzaadi avatar github-actions[bot] avatar glepnir avatar iujakchu avatar juantascon avatar mathjiajia avatar otavioschwanck avatar twistoy avatar xiaoshihou514 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.