A small Neovim plugin to remove trailing whitespace and empty lines at end of file on every save
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mp 1720fb50d0
Merge pull request #2 from mcauley-penney/cfg
3 years ago
lua/tidy chore, docs: 3 years ago
README.md chore, docs: 3 years ago

README.md

tidy.nvim 🧹

A function and autocommand pair that can

- remove all empty lines at the top of the buffer
- remove all trailing whitespace
- remove a variable amount of empty lines at the end of the buffer
- condense multiple empty lines into one

on every BufWritePre.

tidy

install

  • Packer with default configuration and lazy-loading
use{
    "mcauley-penney/tidy.nvim",
     config = function()
        require "tidy".setup{}
    end,
    event  = "BufWritePre"
}

Configuration

default

Tidy comes with the below default configuration:

local M = {
    config = {
        eof_quant = -1,  -- the amount of empty lines to leave at the end of
                         -- the file; -1 = no lines, 0 = 1 line, no limit;
                         -- only applies if "eof" given to "fmts"

        fmts = {         -- the types of formattings to apply
            "eof",       -- removes lines at end of file
            "multi",     -- condenses multiple newlines into one
            "sof",       -- removes lines at start of file
            "ws"         -- removes trailing whitespace
        }
    }
}

how to customize

To customize which formattings will apply, give a list to the setup function:

use{
    "mcauley-penney/tidy.nvim",
    config = function()
        require "tidy".setup{
            fmts = {
                "eof",
                "ws"
            }
       }
   end,
   event  = "BufWritePre"
}

formatting styles

  • eof: remove a variable amount of newlines at end of file

eof

  • multi: condenses multiple newlines into one

condense

  • sof: removes lines at start of file

sof

  • ws: remove whitespace

whitespace

Credits: