Retrail is a small Neovim plugin for managing trailing whitespace. It has two main features:
- Highlight trailing whitespace.
- Trim trailing whitespace upon
:write
.
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()
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,
}
}
:RetrailTrimWhitespace
Trim trailing whitespace:RetrailEnable
Enable trim trailing for the current buffer:RetrailDisable
Disable trim trailing for the current buffer:RetrailToggle
Toggle trim trailing for the current buffer