Skip to content

kaplanz/retrail.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 

Repository files navigation

retrail.nvim

Retrail is a small Neovim plugin for managing trailing whitespace. It has two main features:

  1. Highlight trailing whitespace.
  2. Trim trailing whitespace upon :write.

Installation

Install this plugin using your favorite plugin manager. For example, using lazy:

{
  "kaplanz/retrail.nvim",
  opts = {}, -- calls `setup` using provided `opts`
},

To manually set up the plugin, call the setup function:

require("retrail").setup()

Configuration

While the defaults should work for most users out of the box, the following options can be configured as such:

require("retrail").setup {
  -- Highlight group to use for trailing whitespace.
  hlgroup = "Search",
  -- Pattern to match trailing whitespace against. Edit with caution!
  pattern = "\\v((.*%#)@!|%#)\\s+$",
  -- Enabled filetypes.
  filetype = {
    -- Strictly enable only on `include`ed filetypes. When false, only disabled
    -- on an `exclude`ed filetype.
    strict = false,
    -- Included filetype list.
    include = {},
    -- Excluded filetype list. Overrides `include` list.
    exclude = {
      "",
      "aerial",
      "alpha",
      "checkhealth",
      "cmp_menu",
      "diff",
      "lazy",
      "lspinfo",
      "man",
      "mason",
      "TelescopePrompt",
      "toggleterm",
      "Trouble",
      "WhichKey",
    },
  },
  -- Enabled buftypes.
  buftype = {
    -- Strictly enable only on `include`ed buftypes. When false, only disabled
    -- on an `exclude`ed buftype.
    strict = false,
    -- Included buftype list.
    include = {},
    -- Excluded buftype list. Overrides `include` list.
    exclude = {
      "help",
      "nofile",
      "prompt",
      "quickfix",
      "terminal",
    }
  },
  -- Trim on write behaviour.
  trim = {
    -- Auto trim on BufWritePre
    auto = true,
    -- Trailing whitespace as highlighted.
    whitespace = true,
    -- Final blank (i.e. whitespace only) lines.
    blanklines = false,
  }
}

Commands

  1. :RetrailTrimWhitespace Trim trailing whitespace
  2. :RetrailEnable Enable trim trailing for the current buffer
  3. :RetrailDisable Disable trim trailing for the current buffer
  4. :RetrailToggle Toggle trim trailing for the current buffer